<?php

namespace  App\Http\Controllers\Api\v1\Horoscope;
use App\Http\Controllers\Api\v1\Astro\ThirdprogressedController;
use App\Http\Controllers\Api\v1\Astro\TransitsController;
use Illuminate\Support\Facades\Input;
use App\Models\Api\Recode;
use App\Models\Api\User;
use App\Models\Api\Solarterms;
use App\Models\Api\HoroscopeSetting;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\BaseController;
use DB;
class DataController extends Controller
{
    public $user;
    private $time_type = 0;// 1 真太阳时 || 0 北京时间
    private $time_start = 23;// 0 24点 || 23 子时   日辰初始
    // 十天干
    private $Heavenly_Stems = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"];
    // 十二地支
    private $Earthly_Branches = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"];
    // 五行得分  金 水 木 火 土
    private $score = [
        '金' => 0,
        '水' => 0,
        '木' => 0,
        '火' => 0,
        '土' => 0
    ];
    private $wuxing = [
        '甲' => '木',
        '乙' => '木',
        '丙' => '火',
        '丁' => '火',
        '戊' => '土',
        '己' => '土',
        '庚' => '金',
        '辛' => '金',
        '壬' => '水',
        '癸' => '水',
    ];
    // 五行阴阳
    private $wuxing_yinyang = [
        '甲' => 0,
        '乙' => 1,
        '丙' => 0,
        '丁' => 1,
        '戊' => 0,
        '己' => 1,
        '庚' => 0,
        '辛' => 1,
        '壬' => 0,
        '癸' => 1,
    ];
    // 十神表
    private $shishen = [
        '甲' => [
            '甲' => '比肩',
            '乙' => '劫财',
            '丙' => '偏印',
            '丁' => '正印',
            '戊' => '七杀',
            '己' => '正官',
            '庚' => '偏财',
            '辛' => '正财',
            '壬' => '食神',
            '癸' => '伤官',
        ],
        '乙' => [
            '甲' => '劫财',
            '乙' => '比肩',
            '丙' => '正印',
            '丁' => '偏印',
            '戊' => '正官',
            '己' => '七杀',
            '庚' => '正财',
            '辛' => '偏财',
            '壬' => '伤官',
            '癸' => '食神',
        ],
        '丙' => [
            '甲' => '食神',
            '乙' => '伤官',
            '丙' => '比肩',
            '丁' => '劫财',
            '戊' => '偏印',
            '己' => '正印',
            '庚' => '七杀',
            '辛' => '正官',
            '壬' => '偏财',
            '癸' => '正财',
        ],
        '丁' => [
            '甲' => '伤官',
            '乙' => '食神',
            '丙' => '劫财',
            '丁' => '比肩',
            '戊' => '正印',
            '己' => '偏印',
            '庚' => '正官',
            '辛' => '七杀',
            '壬' => '正财',
            '癸' => '偏财',
        ],
        '戊' => [
            '甲' => '偏财',
            '乙' => '正财',
            '丙' => '食神',
            '丁' => '伤官',
            '戊' => '比肩',
            '己' => '劫财',
            '庚' => '偏印',
            '辛' => '正印',
            '壬' => '七杀',
            '癸' => '正官',
        ],
        '己' => [
            '甲' => '正财',
            '乙' => '偏财',
            '丙' => '伤官',
            '丁' => '食神',
            '戊' => '劫财',
            '己' => '比肩',
            '庚' => '正印',
            '辛' => '偏印',
            '壬' => '正官',
            '癸' => '七杀',
        ],
        '庚' => [
            '甲' => '七杀',
            '乙' => '正官',
            '丙' => '偏财',
            '丁' => '正财',
            '戊' => '食神',
            '己' => '伤官',
            '庚' => '比肩',
            '辛' => '劫财',
            '壬' => '偏印',
            '癸' => '正印',
        ],
        '辛' => [
            '甲' => '正官',
            '乙' => '七杀',
            '丙' => '正财',
            '丁' => '偏财',
            '戊' => '伤官',
            '己' => '食神',
            '庚' => '劫财',
            '辛' => '比肩',
            '壬' => '正印',
            '癸' => '偏印',
        ],
        '壬' => [
            '甲' => '偏印',
            '乙' => '正印',
            '丙' => '七杀',
            '丁' => '正官',
            '戊' => '偏财',
            '己' => '正财',
            '庚' => '食神',
            '辛' => '伤官',
            '壬' => '比肩',
            '癸' => '劫财',
        ],
        '癸' => [
            '甲' => '正印',
            '乙' => '偏印',
            '丙' => '正官',
            '丁' => '七杀',
            '戊' => '正财',
            '己' => '偏财',
            '庚' => '伤官',
            '辛' => '食神',
            '壬' => '劫财',
            '癸' => '比肩',
        ],
    ];
    // 藏干
    private $canggan = [
        '亥' => ['壬', '甲'],
        '子' => ['癸'],
        '丑' => ['己', '癸', '辛'],
        '寅' => ['甲', '丙', '戊'],
        '卯' => ['乙'],
        '辰' => ['戊', '乙', '癸'],
        '巳' => ['丙', '戊', '庚'],
        '午' => ['丁', '己',],
        '未' => ['己', '丁', '乙'],
        '申' => ['庚', '壬', '戊'],
        '酉' => ['辛'],
        '戌' => ['戊', '丁', '辛']
    ];
    // 神煞
    private $shensha = [
        '华盖' => [
            '寅' => '戌',
            '午' => '戌',
            '戌' => '戌',
            '亥' => '未',
            '卯' => '未',
            '未' => '未',
            '申' => '辰',
            '子' => '辰',
            '辰' => '辰',
            '巳' => '丑',
            '酉' => '丑',
            '丑' => '丑',
        ],
        '桃花' => [
            '寅' => '卯',
            '午' => '卯',
            '戌' => '卯',
            '亥' => '子',
            '卯' => '子',
            '未' => '子',
            '申' => '酉',
            '子' => '酉',
            '辰' => '酉',
            '巳' => '午',
            '酉' => '午',
            '丑' => '午',
        ],
        '驿马' => [
            '寅' => '申',
            '午' => '申',
            '戌' => '申',
            '亥' => '巳',
            '卯' => '巳',
            '未' => '巳',
            '申' => '寅',
            '子' => '寅',
            '辰' => '寅',
            '巳' => '亥',
            '酉' => '亥',
            '丑' => '亥',
        ],
        '亡神' => [
            '寅' => '巳',
            '午' => '巳',
            '戌' => '巳',
            '亥' => '寅',
            '卯' => '寅',
            '未' => '寅',
            '申' => '亥',
            '子' => '亥',
            '辰' => '亥',
            '巳' => '申',
            '酉' => '申',
            '丑' => '申',
        ],
        '将星' => [
            '寅' => '午',
            '午' => '午',
            '戌' => '午',
            '亥' => '卯',
            '卯' => '卯',
            '未' => '卯',
            '申' => '子',
            '子' => '子',
            '辰' => '子',
            '巳' => '酉',
            '酉' => '酉',
            '丑' => '酉',
        ],

        '天乙贵人' => [
            '甲' => ['丑', '未'],
            '乙' => ['子', '申'],
            '丙' => ['酉', '亥'],
            '丁' => ['酉', '亥'],
            '戊' => ['丑', '未'],
            '己' => ['子', '申'],
            '庚' => ['丑', '未'],
            '辛' => ['寅', '午'],
            '壬' => ['巳', '卯'],
            '癸' => ['巳', '卯'],
        ],
        '天德贵人' => [
            '寅' => '丁',
            '卯' => '申',
            '辰' => '壬',
            '巳' => '辛',
            '午' => '亥',
            '未' => '甲',
            '申' => '癸',
            '酉' => '寅',
            '戌' => '丙',
            '亥' => '乙',
            '子' => '巳',
            '丑' => '庚',
        ],
        '文昌贵人' => [
            '甲' => '巳',
            '乙' => '午',
            '丙' => '申',
            '丁' => '酉',
            '戊' => '申',
            '己' => '酉',
            '庚' => '亥',
            '辛' => '子',
            '壬' => '寅',
            '癸' => '卯',
        ],
        '月德贵人' => [
            '申' => '壬',
            '子' => '壬',
            '辰' => '壬',
            '寅' => '丙',
            '午' => '丙',
            '戌' => '丙',
            '巳' => '庚',
            '酉' => '庚',
            '丑' => '庚',
            '亥' => '甲',
            '卯' => '甲',
            '未' => '甲',
        ],
        '金舆' => [
            '甲' => '辰',
            '乙' => '巳',
            '丙' => '未',
            '丁' => '申',
            '戊' => '未',
            '己' => '申',
            '庚' => '戌',
            '辛' => '亥',
            '壬' => '丑',
            '癸' => '寅',
        ],
        '红艳煞' => [
            '甲' => '午',
            '乙' => '申',
            '丙' => '寅',
            '丁' => '未',
            '戊' => '辰',
            '己' => '辰',
            '庚' => '申',
            '辛' => '酉',
            '壬' => '子',
            '癸' => '戌',
        ],
        '孤辰' => [
            '亥' => '寅',
            '子' => '寅',
            '丑' => '寅',
            '寅' => '巳',
            '卯' => '巳',
            '辰' => '巳',
            '巳' => '申',
            '午' => '申',
            '未' => '申',
            '申' => '亥',
            '酉' => '亥',
            '戌' => '亥',
        ],
        '寡宿' => [
            '亥' => '戌',
            '子' => '戌',
            '丑' => '戌',
            '寅' => '丑',
            '卯' => '丑',
            '辰' => '丑',
            '巳' => '辰',
            '午' => '辰',
            '未' => '辰',
            '申' => '未',
            '酉' => '未',
            '戌' => '未',
        ],
        '禄神' => [
            '甲' => '寅',
            '乙' => '卯',
            '丙' => '巳',
            '丁' => '午',
            '戊' => '巳',
            '己' => '午',
            '庚' => '申',
            '辛' => '酉',
            '壬' => '亥',
            '癸' => '子',
        ],
        '羊刃' => [
            '甲' => '卯',
            '乙' => '辰',
            '丙' => '午',
            '丁' => '未',
            '戊' => '午',
            '己' => '未',
            '庚' => '酉',
            '辛' => '戌',
            '壬' => '子',
            '癸' => '丑',
        ],
        '金神' => [
            '癸酉', '己巳', '乙丑'
        ],
    ];
    // 长生十二宫
    private $changsheng = [
        '甲' => [
            '子' => '沐浴',
            '丑' => '冠带',
            '寅' => '临官',
            '卯' => '帝旺',
            '辰' => '衰',
            '巳' => '病',
            '午' => '死',
            '未' => '墓',
            '申' => '绝',
            '酉' => '胎',
            '戌' => '养',
            '亥' => '长生',
        ],
        '乙' => [
            '巳' => '沐浴',
            '辰' => '冠带',
            '卯' => '临官',
            '寅' => '帝旺',
            '丑' => '衰',
            '子' => '病',
            '亥' => '死',
            '戌' => '墓',
            '酉' => '绝',
            '申' => '胎',
            '未' => '养',
            '午' => '长生',
        ],
        '丙' => [
            '子' => '胎',
            '丑' => '养',
            '寅' => '长生',
            '卯' => '沐浴',
            '辰' => '冠带',
            '巳' => '临官',
            '午' => '帝旺',
            '未' => '衰',
            '申' => '病',
            '酉' => '死',
            '戌' => '墓',
            '亥' => '绝',
        ],
        '丁' => [
            '申' => '沐浴',
            '未' => '冠带',
            '午' => '临官',
            '巳' => '帝旺',
            '辰' => '衰',
            '卯' => '病',
            '寅' => '死',
            '丑' => '墓',
            '子' => '绝',
            '亥' => '胎',
            '戌' => '养',
            '酉' => '长生',
        ],
        '戊' => [
            '子' => '胎',
            '丑' => '养',
            '寅' => '长生',
            '卯' => '沐浴',
            '辰' => '冠带',
            '巳' => '临官',
            '午' => '帝旺',
            '未' => '衰',
            '申' => '病',
            '酉' => '死',
            '戌' => '墓',
            '亥' => '绝',
        ],
        '己' => [
            '申' => '沐浴',
            '未' => '冠带',
            '午' => '临官',
            '巳' => '帝旺',
            '辰' => '衰',
            '卯' => '病',
            '寅' => '死',
            '丑' => '墓',
            '子' => '绝',
            '亥' => '胎',
            '戌' => '养',
            '酉' => '长生',
        ],
        '庚' => [
            '午' => '沐浴',
            '未' => '冠带',
            '申' => '临官',
            '酉' => '帝旺',
            '戌' => '衰',
            '亥' => '病',
            '子' => '死',
            '丑' => '墓',
            '寅' => '绝',
            '卯' => '胎',
            '辰' => '养',
            '巳' => '长生',
        ],
        '辛' => [
            '亥' => '沐浴',
            '戌' => '冠带',
            '酉' => '临官',
            '申' => '帝旺',
            '未' => '衰',
            '午' => '病',
            '巳' => '死',
            '辰' => '墓',
            '卯' => '绝',
            '寅' => '胎',
            '丑' => '养',
            '子' => '长生',
        ],
        '壬' => [
            '酉' => '沐浴',
            '戌' => '冠带',
            '亥' => '临官',
            '子' => '帝旺',
            '丑' => '衰',
            '寅' => '病',
            '卯' => '死',
            '辰' => '墓',
            '巳' => '绝',
            '午' => '胎',
            '未' => '养',
            '申' => '长生',
        ],
        '癸' => [
            '寅' => '沐浴',
            '丑' => '冠带',
            '子' => '临官',
            '亥' => '帝旺',
            '戌' => '衰',
            '酉' => '病',
            '申' => '死',
            '未' => '墓',
            '午' => '绝',
            '巳' => '胎',
            '辰' => '养',
            '卯' => '长生',
        ],
    ];

    private $Chinese_era = [];

    private $userinfo = [];

    private $bazi = [
        1 => '甲', 2 => '戌',
        3 => '丙', 4 => '子',
        5 => '丁', 6 => '亥',
        7 => '丁', 8 => '未'
    ];

    private $sex = 2;

    private $st_time = null;

    private $birth_sun_deg = null;

    private $birth_time = null;

    private $return_birth_time = null;

    private $dayun = null;

    /**
     * @param bool $self
     * @param string $setting
     * @throws \app\common\lib\exception\ApiException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function initload($self = false, $setting = 'user')
    {
        $this->Chinese_era = config('horoscope.chinese_era');// 获取六十甲子

        $uid = $request->uid;

        $Recode = new Recode();

        if ($self !== false) {
            $userinfo = $Recode->getSelfRecode(['uid' => $request->uid]);
        } else {
            $id = (Input::get('id') ?? Input::get('rid'));

            $userinfo = $Recode->getRecode(['id' => $id]);
        }

        if (empty($userinfo)) {
            echo json_encode(['code' => 10801, 'msg' => 'User info is not exist.']);
            exit;
        }
        if ($userinfo['type'] != 1 && $userinfo['type'] != 2) {
            echo json_encode(['code' => 10801, 'msg' => 'Sex is Invalid.']);
            exit;
        }

        $this->sex = $userinfo['type'];

        $this->birth_time = $this->return_birth_time = strtotime("{$userinfo['year']}-{$userinfo['month']}-{$userinfo['day']} {$userinfo['hour']}:{$userinfo['minute']}");
        if ($userinfo['is_summer']) {
            $this->birth_time = $this->birth_time - 3600;
        }
        if ($setting === 'user') {
            $setting = HoroscopeSetting::where(['uid'=>$uid])->first(['type','start']);
        } else {
            $setting = ['type' => 1, 'start' => 0];
        }


        // type 1 真太阳时  0 北京时间
        // start 0 24点    23 23点   日辰初始
        if (!empty($setting) && isset($setting['type']) && $setting['type'] == 1) $this->time_type = 1;
        if (!empty($setting) && isset($setting['start']) && $setting['start'] == 0) $this->time_start = 0;
        // 默认使用北京时间 若为真太阳时则：
        if ($this->time_type == 1) {
            $longitude = ($userinfo['long_deg'] + $userinfo['long_min'] / 60) * $userinfo['ew'];
            $this->birth_time = $this->birth_time + ($longitude * $userinfo['ew'] - $userinfo['timezone'] * 15 * $userinfo['ew']) * 4 * 60;

            $userinfo['year'] = intval(date('Y', $this->birth_time));
            $userinfo['month'] = intval(date('m', $this->birth_time));
            $userinfo['day'] = intval(date('d', $this->birth_time));
            $userinfo['hour'] = intval(date('H', $this->birth_time));
            $userinfo['minute'] = intval(date('i', $this->birth_time));
        }

        $this->birth_sun_deg = $this->getSunDeg($this->birth_time);

        $this->userinfo = $userinfo;


        $this->getBazi($userinfo);// 获取八字
//            // ---- for test ----
//            $this->bazi = [
//                1 => '丁', 2 => '酉',
//                3 => '甲', 4 => '辰',
//                5 => '丁', 6 => '丑',
//                7 => '丙', 8 => '午'
//            ];

        $this->dayun();

    }

    // 加载html页面
    public function index()
    {
         return view('web/horoscope.data');
    }


    public function refresh(Request $request)
    {
        $ucid = $request->input('ucid');

        if (!$ucid) exit;

        $this->user = User::where(['uc_id' => $ucid])->first();

        if (empty($this->user)) exit;

        $this->initload(false, 'user');// 八字等信息初始化

        $return = [
            'birth_time' => date('Y.m.d H:i', $this->return_birth_time),
            'sex' => $this->sex,
            'bazi' => $this->bazi,
        ];
        $shishen = $this->getShishen();
        $shishen1 = [
            $this->shishen_to_easy($shishen['gan'][1]['relation']),
            $this->shishen_to_easy($shishen['gan'][3]['relation']),
            '日元',
            $this->shishen_to_easy($shishen['gan'][7]['relation']),
        ];
        $shishen2 = [];
        foreach ($shishen['cang'] as $k => $cang) {
            $shishen2[$k] = '';
            foreach ($cang as $cg) {
                $shishen2[$k] .= $this->shishen_to_easy($cg['relation']);
            }
        }
        // 食神关系
        $return['shishen1'] = $shishen1;
        $return['shishen2'] = array_values($shishen2);
        //  藏干
        $return['canggan'] = [
            $this->canggan[$this->bazi[2]],
            $this->canggan[$this->bazi[4]],
            $this->canggan[$this->bazi[6]],
            $this->canggan[$this->bazi[8]],
        ];

        // 长生十二宫
        $return['changsheng'] = [
            $this->changsheng[$this->bazi[5]][$this->bazi[2]],
            $this->changsheng[$this->bazi[5]][$this->bazi[4]],
            $this->changsheng[$this->bazi[5]][$this->bazi[6]],
            $this->changsheng[$this->bazi[5]][$this->bazi[8]],
        ];
        // 纳音关系
        $return['nayin'] = [
            $this->getNayin($this->bazi[1], $this->bazi[2]),
            $this->getNayin($this->bazi[3], $this->bazi[4]),
            $this->getNayin($this->bazi[5], $this->bazi[6]),
            $this->getNayin($this->bazi[7], $this->bazi[8]),
        ];
        // 空亡
        $return['kongwang'] = [
            $this->getKongwang($this->bazi[1], $this->bazi[2]),
            $this->getKongwang($this->bazi[3], $this->bazi[4]),
            $this->getKongwang($this->bazi[5], $this->bazi[6]),
            $this->getKongwang($this->bazi[7], $this->bazi[8]),
        ];

        $return['wuxing'] = $this->get_wuxing_percent();
        $return['start_time'] = date('Y.m.d', $this->st_time);
        $return['start_year_old'] = sprintf("%.1f", abs($this->st_time - $this->birth_time) / (3600 * 24 * 365)) * 1;
        $return['geju'] = $this->get_structure($this->bazi);

        $timeNow = time();
        // 大运
        $st_year = intval(date('Y', $this->st_time));// 大运起
        $num = 0;
     if($this->st_time > $timeNow)
        {
            $d_status = $l_status = 1;
        }else{
            $d_status = $l_status = -1;
        }


        $liunian_yearstembranche = $this->getYearStemBranche(date('Y'));
        if(date('m') < 3 && $this->getSundeg(time()) < 315)
        {
            $liunian_yearstembranche--;
            if($liunian_yearstembranche < 0) $liunian_yearstembranche = 59;
        }
        $liunian_now = $this->Chinese_era[$liunian_yearstembranche];

        for ($j = $st_year; $j <= $st_year + 50; $j += 10) {
            if ($d_status === -1 && date('Y') > $j && date('Y') <= $j + 10) $d_status = 0;
            elseif ($d_status === 0 && date('Y') < $j) $d_status = 1;


            $return['dayun'][0][] = ['name' => $this->dayun[$num], 'status' => $d_status];
            // 大运 干支
            $return['dayun'][1][] = ['name' => $j, 'status' => $d_status];
            $s = 2;
            for ($i = $j; $i < $j + 10; $i++) {
               /* if (date('Y') >= $i && date('Y') < $i + 1) $l_status = 0;
                elseif (date('Y') < $i) $l_status = 1;*/
                $y_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($i)];

                 if($l_status === -1 && $liunian_now == $y_gan_zhi) $l_status = 0;
                elseif($l_status === 0) $l_status = 1;
                $return['dayun'][$s][] = ['name' => $y_gan_zhi, 'status' => $l_status];
                $s++;
            }
            $return['dayun'][12][] = ['name' => $i - 1, 'status' => $d_status];
            $num++;
        }

        $return['time_start'] = $this->time_start;
        $return['time_type'] = $this->time_type;

        return response()->json(['code' => 200, 'data' => $return, 'msg' => 'ok']);
//        $this->assign('url_data',json_encode(['code'=>200,'data'=>$return,'msg'=>'ok']));
//
//        return $this->fetch();
    }

    public function get_score_by_ajax(Request $request)
    {
        $year = intval($request->input('year'));
        $end = intval($request->input('end'));// 计算的年数  如计算十年   $end=10;
        if (!$year) $year = intval(date("Y"));
        if ($end <= 0) $end = 0;

        $ret['bazi'] = implode($this->bazi);
        $ret['birth_sun_deg'] = $this->birth_sun_deg;
        $ret['sex'] = $this->sex;

        $temp['bazi'] = implode($this->bazi);
        $temp['birth_sun_deg'] = $this->birth_sun_deg;
        $temp['sex'] = $this->sex;

        $st_year = date('Y', $this->st_time);
        $num = 0;
        for ($j = $year; $j <= $year + $end; $j++) {
            for ($i = $st_year; $i < $j; $i += 10) if ($j >= $i && $j < $i + 10) $st_year = $i;

            // 大运 干支
            $d_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($st_year)];
            $d_gan = mb_substr($d_gan_zhi, 0, 1, 'utf-8');// 大运天干
            $d_zhi = mb_substr($d_gan_zhi, 1, 1, 'utf-8');// 大运地支
            $dazhi = $this->canggan[$d_zhi][0];// 大运地支本气
            $y_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($j)];
            $y_gan = mb_substr($y_gan_zhi, 0, 1, 'utf-8');// 流年天干
            $y_zhi = mb_substr($y_gan_zhi, 1, 1, 'utf-8');// 流年地支
            $liuzhi = $this->canggan[$y_zhi][0];// 流年地支本气
            $rizhi = $this->canggan[$this->bazi[6]][0];// 本命地支本气

            $ret['taohua'][$num]['year'] = $j;
            $ret['taohua'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['taohua'][$num]['dayun_gan'] = $d_gan;
//            $ret['taohua'][$num]['dayun_zhi'] = $d_zhi;
            $ret['taohua'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['taohua'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['taohua'][$num]['liunian_gan'] = $y_gan;
//            $ret['taohua'][$num]['liunian_zhi'] = $y_zhi;
            $ret['taohua'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['taohua'][$num]['liunian_zhiqi'] = $liuzhi;

            $taohua = 0;
            // 1.干财官
            if (
                // 男命，流年天干为正财或偏财【+15】
                ($this->sex == 1 && ($this->shishen[$y_gan][$this->bazi[5]] == '正财'
                        || $this->shishen[$y_gan][$this->bazi[5]] == '偏财'))
                ||
                // 女命，流年天干为七杀或正官【+15】
                ($this->sex == 2 && ($this->shishen[$y_gan][$this->bazi[5]] == '七杀'
                        || $this->shishen[$y_gan][$this->bazi[5]] == '正官'))
            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '干财官:男命，流年天干为正财或偏财;女命，流年天干为七杀或正官.',
                    'add' => 15,
                ];
                $taohua += 15;
                // 此时地支为日干之禄【+15】
                if ($this->is_lushen($this->bazi[5], $y_zhi)) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '干财官:男命，流年天干为正财或偏财;女命，流年天干为七杀或正官. 此时地支为日干之禄',
                        'add' => 15,
                    ];
                    $taohua += 15;
                }
                // 此时地支为日支【+12】
                if ($this->bazi[6] == $y_zhi) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '干财官:男命，流年天干为正财或偏财;女命，流年天干为七杀或正官.此时地支为日支',
                        'add' => 15,
                    ];
                    $taohua += 12;
                }
            }
            // 2.支财官
            if (
                // 男命，流年地支为正财或偏财【+12】
                ($this->sex == 1 && ($this->shishen[$liuzhi][$this->bazi[5]] == '正财'
                        || $this->shishen[$liuzhi][$this->bazi[5]] == '偏财'))
                ||
                // 女命，流年地支为七杀或正官【+12】
                ($this->sex == 2 && ($this->shishen[$liuzhi][$this->bazi[5]] == '七杀'
                        || $this->shishen[$liuzhi][$this->bazi[5]] == '正官'))
            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '支财官:男命，流年地支为正财或偏财;女命，流年地支为七杀或正官.',
                    'add' => 12,
                ];
                $taohua += 12;
                // 此时天干为比肩【+13】
                if ($this->shishen[$y_gan][$this->bazi[5]] == '比肩') {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '支财官:男命，流年地支为正财或偏财;女命，流年地支为七杀或正官.此时天干为比肩',
                        'add' => 13,
                    ];
                    $taohua += 13;
                }
                // 此时天干与日干相合【+15】
                if ($this->is_liuhe($y_gan, $this->bazi[5])) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '支财官:男命，流年地支为正财或偏财;女命，流年地支为七杀或正官.此时天干与日干相合',
                        'add' => 15,
                    ];
                    $taohua += 15;
                }
            }
            // 3.天地合 流年地支与日支合【+8】
            if ($this->is_liuhe($y_zhi, $this->bazi[6])) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '天地合:流年地支与日支合.',
                    'add' => 8,
                ];
                $taohua += 8;
                // 此时天干也与日干合【+8】
                if ($this->is_liuhe($y_gan, $this->bazi[5])) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '天地合:流年地支与日支合.此时天干也与日干合',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
                // 此时日支为财（男）或官杀（女）【+8】
                if (
                    // 此时日支为财（男）【+8】
                    ($this->sex == 1 && ($this->shishen[$rizhi][$this->bazi[5]] == '正财'
                            || $this->shishen[$rizhi][$this->bazi[5]] == '偏财'))
                    ||
                    // 此时日支为官杀（女）【+8】
                    ($this->sex == 2 && ($this->shishen[$rizhi][$this->bazi[5]] == '七杀'
                            || $this->shishen[$rizhi][$this->bazi[5]] == '正官'))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '天地合:流年地支与日支合.此时日支为财（男）或官杀（女）',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            }
            // 4.冲日支
            if ($this->is_liuchong($y_zhi, $this->bazi[6])) {
                if (
                    // 此时流支为财（男）【+7】
                    ($this->sex == 1 && ($this->shishen[$liuzhi][$this->bazi[5]] == '正财'
                            || $this->shishen[$liuzhi][$this->bazi[5]] == '偏财'))
                    ||
                    // 此时流支为官杀（女）【+7】
                    ($this->sex == 2 && ($this->shishen[$liuzhi][$this->bazi[5]] == '七杀'
                            || $this->shishen[$liuzhi][$this->bazi[5]] == '正官'))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '冲日支:此时流支为财;此时流支为官杀.',
                        'add' => 7,
                    ];
                    $taohua += 7;
                }
                if (
                    // 此时日支为财（男）【+7】
                    ($this->sex == 1 && ($this->shishen[$rizhi][$this->bazi[5]] == '正财'
                            || $this->shishen[$rizhi][$this->bazi[5]] == '偏财'))
                    ||
                    // 此时日支为官杀（女）【+7】
                    ($this->sex == 2 && ($this->shishen[$rizhi][$this->bazi[5]] == '七杀'
                            || $this->shishen[$rizhi][$this->bazi[5]] == '正官'))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '冲日支:此时日支为财;此时日支为官杀.',
                        'add' => 7,
                    ];
                    $taohua += 7;
                }
                // 此时流干为比肩【+7】
                if ($this->shishen[$y_gan][$this->bazi[5]] == '比肩') {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '冲日支:此时流干为比肩.',
                        'add' => 7,
                    ];
                    $taohua += 7;
                }
                // 此时日支在命局或大运中被合【+7】
                if (
                    $this->is_liuhe($this->bazi[6], $this->bazi[2])
                    || $this->is_liuhe($this->bazi[6], $this->bazi[4])
                    || $this->is_liuhe($this->bazi[6], $this->bazi[8])
                    || $this->is_liuhe($this->bazi[6], $d_zhi)
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '冲日支:此时日支在命局或大运中被合.',
                        'add' => 7,
                    ];
                    $taohua += 7;
                }
                // 此时日支为辰戌丑未【+3】
                if (in_array($this->bazi[6], ['辰', '戌', '丑', '未'])) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '冲日支:此时日支为辰戌丑未.',
                        'add' => 3,
                    ];
                    $taohua += 3;
                }
            }
            // 5.桃花年：流年地支为日支所起的桃花【+5】
            if ($this->is_taohua($this->bazi[6], $y_zhi)) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '桃花年：流年地支为日支所起的桃花.',
                    'add' => 5,
                ];
                $taohua += 5;
            }
            // 流年地支为年支所起的桃花且流年地支在本命中或大运存在【+5】
            if (
                $this->is_taohua($this->bazi[2], $y_zhi)
                && (
                    $this->bazi[4] == $y_zhi
                    || $this->bazi[4] == $y_zhi
                    || $this->bazi[4] == $y_zhi
                    || $d_zhi == $y_zhi
                )
            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '流年地支为年支所起的桃花且流年地支在本命中或大运存在.',
                    'add' => 5,
                ];
                $taohua += 5;
            }
            // 6.合留 若原命局地支或大运地支本气财星（男）或本气官星（女）被冲或穿，流年地支来合【+8】
            $temp_arr = [$this->bazi[2], $this->bazi[4], $this->bazi[6], $this->bazi[8], $d_zhi];
            // 本命年支
            if (
                // 流年地支来合
                $this->is_liuhe($y_zhi, $this->bazi[2]) &&
                // 被冲或穿
                ($this->liuchong($this->bazi[2], $temp_arr) || $this->liuhai($this->bazi[2], $temp_arr))

            ) {
                if (
                    ($this->sex == 1 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[2]][0]][$this->bazi[5]], ['偏财', '正财']))
                    ||
                    ($this->sex == 2 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[2]][0]][$this->bazi[5]], ['七杀', '正官']))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '合留:若原命局年支本气财星（男）或本气官星（女）被冲或穿，流年地支来合.',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            } // 本命月支
            elseif (
                // 流年地支来合
                $this->is_liuhe($y_zhi, $this->bazi[4]) &&
                // 被冲或穿
                ($this->liuchong($this->bazi[4], $temp_arr) || $this->liuhai($this->bazi[4], $temp_arr))

            ) {
                if (
                    ($this->sex == 1 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[4]][0]][$this->bazi[5]], ['偏财', '正财']))
                    ||
                    ($this->sex == 2 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[4]][0]][$this->bazi[5]], ['七杀', '正官']))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '合留:若原命局月支本气财星（男）或本气官星（女）被冲或穿，流年地支来合.',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            } // 本命日支
            elseif (
                // 流年地支来合
                $this->is_liuhe($y_zhi, $this->bazi[6]) &&
                // 被冲或穿
                ($this->liuchong($this->bazi[6], $temp_arr) || $this->liuhai($this->bazi[6], $temp_arr))

            ) {
                if (
                    ($this->sex == 1 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[6]][0]][$this->bazi[5]], ['偏财', '正财']))
                    ||
                    ($this->sex == 2 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[6]][0]][$this->bazi[5]], ['七杀', '正官']))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '合留:若原命局日支本气财星（男）或本气官星（女）被冲或穿，流年地支来合.',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            } // 本命时支
            elseif (
                // 流年地支来合
                $this->is_liuhe($y_zhi, $this->bazi[8]) &&
                // 被冲或穿
                ($this->liuchong($this->bazi[8], $temp_arr) || $this->liuhai($this->bazi[8], $temp_arr))

            ) {
                if (
                    ($this->sex == 1 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[8]][0]][$this->bazi[5]], ['偏财', '正财']))
                    ||
                    ($this->sex == 2 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[8]][0]][$this->bazi[5]], ['七杀', '正官']))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '合留:若原命局时支本气财星（男）或本气官星（女）被冲或穿，流年地支来合.',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            } // 大运地支
            elseif (
                // 流年地支来合
                $this->is_liuhe($y_zhi, $d_zhi) &&
                // 被冲或穿
                ($this->liuchong($d_zhi, $temp_arr) || $this->liuhai($d_zhi, $temp_arr))

            ) {
                if (
                    ($this->sex == 1 &&
                        in_array($this->shishen[$dazhi][$this->bazi[5]], ['偏财', '正财']))
                    ||
                    ($this->sex == 2 &&
                        in_array($this->shishen[$dazhi][$this->bazi[5]], ['七杀', '正官']))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '合留:若原命局大运地支本气财星（男）或本气官星（女）被冲或穿，流年地支来合.',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            }
            // 7.运财官 大运地支本气为财（男）或官杀（女），流年地支合之【+10】，流年地支拱之【+7】，流年地支冲之【+5】，
            if (
                ($this->sex == 1 && in_array($this->shishen[$dazhi][$this->bazi[5]], ['偏财', '正财']))
                || ($this->sex == 2 && in_array($this->shishen[$dazhi][$this->bazi[5]], ['七杀', '正官']))
            ) {
                if ($this->is_liuhe($y_zhi, $d_zhi)) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '运财官 大运地支本气为财（男）或官杀（女），流年地支合之.',
                        'add' => 10,
                    ];
                    $taohua += 10;
                }
                if ($this->is_gong($y_zhi, $d_zhi)) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '运财官 大运地支本气为财（男）或官杀（女），流年地支拱之.',
                        'add' => 7,
                    ];
                    $taohua += 7;
                }
                if ($this->is_liuchong($y_zhi, $d_zhi)) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '运财官 大运地支本气为财（男）或官杀（女），流年地支冲之.',
                        'add' => 5,
                    ];
                    $taohua += 5;
                }
            }
            // 8.禄出干 流年天干是财（男）或官杀（女），且其禄为本命地支或大运地支之一，【+8】
            if (
                (($this->sex == 1 && in_array($this->shishen[$y_gan][$this->bazi[5]], ['偏财', '正财']))
                    || ($this->sex == 2 && in_array($this->shishen[$y_gan][$this->bazi[5]], ['七杀', '正官'])))
                && (
                    $this->is_lushen($y_gan, $this->bazi[2])
                    || $this->is_lushen($y_gan, $this->bazi[4])
                    || $this->is_lushen($y_gan, $this->bazi[6])
                    || $this->is_lushen($y_gan, $this->bazi[8])
                    || $this->is_lushen($y_gan, $d_zhi)
                )
            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '禄出干:流年天干是财（男）或官杀（女），且其禄为本命地支或大运地支之一.',
                    'add' => 8,
                ];
                $taohua += 8;
            }
            // 9.宫出干 流年天干的禄是日支【+9】；
            if ($this->is_lushen($y_gan, $this->bazi[6])) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '宫出干:流年天干的禄是日支.',
                    'add' => 9,
                ];
                $taohua += 9;
            }
            // 日支是辰戌丑未，流干是日支非土藏干之一【+7】
            if (
                in_array($this->bazi[6], ['辰', '戌', '丑', '未'])
                && in_array($y_gan, [$this->canggan[$this->bazi[6]][1], $this->canggan[$this->bazi[6]][2]])
            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '日支是辰戌丑未，流干是日支非土藏干之一.',
                    'add' => 7,
                ];
                $taohua += 7;
                // 此时日干是壬癸【+3】
                if ($this->bazi[5] == '壬' || $this->bazi[5] == '癸') {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '日支是辰戌丑未，流干是日支非土藏干之一.此时日干是壬癸',
                        'add' => 3,
                    ];
                    $taohua += 3;
                }
            }
            // 10.支伏吟 若流年地支是四柱或大运地支有本气财（男）或官杀（女）【+6】
            if (in_array($y_zhi, $temp_arr) &&
                (($this->sex == 1 && in_array($this->shishen[$liuzhi][$this->bazi[5]], ['偏财', '正财']))
                    || ($this->sex == 2 && in_array($this->shishen[$liuzhi][$this->bazi[5]], ['七杀', '正官'])))

            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '支伏吟:若流年地支是四柱或大运地支有本气财（男）或官杀（女）',
                    'add' => 6,
                ];
                $taohua += 6;
            }
            // 11.宫伏吟 若流年地支是日支【+6】
            if ($this->bazi[6] == $y_zhi) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '宫伏吟:若流年地支是日支',
                    'add' => 6,
                ];
                $taohua += 6;
            }
            // 12.流年地支拱到日支【+6】
            if ($this->is_gong($this->bazi[6], $y_zhi)) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '流年地支拱到日支',
                    'add' => 6,
                ];
                $taohua += 6;
            }
            // 13.运比肩：流支合或冲运支，若此时运干比肩+3，运支合或拱日支+6，运支合或拱本命财星（男命，此财星是指某柱天干或地支本气）+6
            if ($this->is_liuhe($y_zhi, $d_zhi) || $this->is_liuchong($y_zhi, $d_zhi)) {
                if ($this->shishen[$d_gan][$this->bazi[5]] == '比肩') {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '运比肩：流支合或冲运支，若此时运干比肩',
                        'add' => 3,
                    ];
                    $taohua += 3;
                    if ($this->is_liuhe($this->bazi[6], $d_zhi) || $this->is_gong($this->bazi[6], $d_zhi)) {
                        $ret['taohua'][$num]['condition'][] = [
                            'if' => '运比肩：流支合或冲运支，若此时运干比肩,运支合或拱日支',
                            'add' => 6,
                        ];
                        $taohua += 6;
                    }
                    if ($this->sex == 1) {
                        if (
                            (
                                ($this->is_liuhe($this->bazi[1], $d_zhi)
                                    || $this->is_gong($this->bazi[1], $d_zhi))
                                && in_array($this->shishen[$this->bazi[1]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[3], $d_zhi)
                                    || $this->is_gong($this->bazi[3], $d_zhi))
                                && in_array($this->shishen[$this->bazi[3]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[7], $d_zhi)
                                    || $this->is_gong($this->bazi[7], $d_zhi))
                                && in_array($this->shishen[$this->bazi[7]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[2], $d_zhi)
                                    || $this->is_gong($this->bazi[2], $d_zhi))
                                && in_array($this->shishen[$this->canggan[$this->bazi[2]][0]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[4], $d_zhi)
                                    || $this->is_gong($this->bazi[4], $d_zhi))
                                && in_array($this->shishen[$this->canggan[$this->bazi[4]][0]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[6], $d_zhi)
                                    || $this->is_gong($this->bazi[6], $d_zhi))
                                && in_array($this->shishen[$this->canggan[$this->bazi[6]][0]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[8], $d_zhi)
                                    || $this->is_gong($this->bazi[8], $d_zhi))
                                && in_array($this->shishen[$this->canggan[$this->bazi[8]][0]][$this->bazi[5]], ['偏财', '正财'])
                            )
                        ) {
                            $ret['taohua'][$num]['condition'][] = [
                                'if' => '运比肩：流支合或冲运支，若此时运干比肩,运支合或拱日支,运支合或拱本命财星（男命，此财星是指某柱天干或地支本气）',
                                'add' => 6,
                            ];
                            $taohua += 6;
                        }
                    }
                }
            }
            $Third = new ThirdprogressedController();
            $Third->recode = $this->userinfo;
            $th_4_1 = json_decode($Third->get($j . "-4-1"), true)['data']['planets'];
            $th_10_1 = json_decode($Third->get($j . "-10-1"), true)['data']['planets'];
            $score_4_1 = 0;
            $score_10_1 = 0;
            if (isset($th_4_1[0]['phase']['0-3']) && $th_4_1[0]['phase']['0-3']['phase_e'] == 0) {
                $score_4_1 += 5;
                if (isset($th_4_1[3]['phase']['3-5'])) $score_4_1 += 5;
                if (in_array($th_4_1[3]['in_house_id'], [5, 7])) $score_4_1 += 5;
            }
            if (isset($th_4_1[3]['phase']['3-4']) && $th_4_1[3]['phase']['3-4']['phase_e'] == 0) {
                $score_4_1 += 5;
                if (isset($th_4_1[3]['phase']['3-5'])) $score_4_1 += 5;
                if (in_array($th_4_1[3]['in_house_id'], [5, 7])) $score_4_1 += 5;
            }
            if (isset($th_4_1[0]['phase']['0-4']) && $th_4_1[0]['phase']['0-4']['phase_e'] == 0) {
                $score_4_1 += 2;
                if (isset($th_4_1[4]['phase']['4-5'])) $score_4_1 += 5;
                if (in_array($th_4_1[3]['in_house_id'], [5, 7]) || in_array($th_4_1[4]['in_house_id'], [5, 7])) $score_4_1 += 5;
            }
            if ($score_4_1 == 0 && isset($th_4_1[3]['phase']['3-5'])) {
                $score_4_1 += 5;
                if (in_array($th_4_1[3]['in_house_id'], [5, 7]) || in_array($th_4_1[5]['in_house_id'], [5, 7])) $score_4_1 += 5;
            }
            if (isset($th_10_1[0]['phase']['0-3']) && $th_10_1[0]['phase']['0-3']['phase_e'] == 0) {
                $score_10_1 += 5;
                if (isset($th_10_1[3]['phase']['3-5'])) $score_10_1 += 5;
                if (in_array($th_10_1[3]['in_house_id'], [5, 7])) $score_10_1 += 5;
            }
            if (isset($th_10_1[3]['phase']['3-4']) && $th_10_1[3]['phase']['3-4']['phase_e'] == 0) {
                $score_10_1 += 5;
                if (isset($th_10_1[3]['phase']['3-5'])) $score_10_1 += 5;
                if (in_array($th_10_1[3]['in_house_id'], [5, 7])) $score_10_1 += 5;
            }
            if (isset($th_10_1[0]['phase']['0-4']) && $th_10_1[0]['phase']['0-4']['phase_e'] == 0) {
                $score_10_1 += 2;
                if (isset($th_10_1[4]['phase']['4-5'])) $score_10_1 += 5;
                if (in_array($th_10_1[3]['in_house_id'], [5, 7]) || in_array($th_10_1[4]['in_house_id'], [5, 7])) $score_10_1 += 5;
            }
            if ($score_10_1 == 0 && isset($th_10_1[3]['phase']['3-5'])) {
                $score_10_1 += 5;
                if (in_array($th_10_1[3]['in_house_id'], [5, 7]) || in_array($th_10_1[5]['in_house_id'], [5, 7])) $score_10_1 += 5;
            }
            if ($score_4_1 > $score_10_1) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '三限4月1日',
                    'add' => $score_4_1,
                ];
                $taohua += $score_4_1;
            } else {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '三限10月1日',
                    'add' => $score_10_1,
                ];
                $taohua += $score_10_1;
            }
            $lv = 0;
            if ($taohua >= 30) $lv = 3;
            elseif ($taohua >= 20) $lv = 2;
            elseif ($taohua > 10) $lv = 1;
            $ret['taohua'][$num]['score'] = $taohua;
            $ret['taohua'][$num]['lv'] = $lv . '级';


            $ret['hunpei'][$num] = [];
            $ret['hunpei'][$num]['year'] = $j;
            $ret['hunpei'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['hunpei'][$num]['dayun_gan'] = $d_gan;
//            $ret['hunpei'][$num]['dayun_zhi'] = $d_zhi;
            $ret['hunpei'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['hunpei'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['hunpei'][$num]['liunian_gan'] = $y_gan;
//            $ret['hunpei'][$num]['liunian_zhi'] = $y_zhi;
            $ret['hunpei'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['hunpei'][$num]['liunian_zhiqi'] = $liuzhi;
//            if($taohua < 10) continue;// 前提：桃花10分以上（若不满足这个条件，婚配得分无效）
            ####################婚配######################
            $hunpei = 0;
            // 1、   印年：流干为印+10，流支本气为印+10；
            if ($this->is_ygs($y_gan, $this->bazi[5], '印')) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '印年：流干为印+10，',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            if ($this->is_ygs($liuzhi, $this->bazi[5], '印')) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '印年：流支本气为印+10；',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            // 2、   冲合印：流支冲或合本命或大运印支+10；
            if (
                (
                    $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '印')
                    &&
                    (
                        $this->is_liuchong($this->bazi[2], $y_zhi)
                        || $this->is_liuhe($this->bazi[2], $y_zhi)
                    )
                )
                ||
                (
                    $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '印')
                    &&
                    (
                        $this->is_liuchong($this->bazi[4], $y_zhi)
                        || $this->is_liuhe($this->bazi[4], $y_zhi)
                    )
                )
                ||
                (
                    $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '印')
                    &&
                    (
                        $this->is_liuchong($this->bazi[6], $y_zhi)
                        || $this->is_liuhe($this->bazi[6], $y_zhi)
                    )
                )
                ||
                (
                    $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '印')
                    &&
                    (
                        $this->is_liuchong($this->bazi[8], $y_zhi)
                        || $this->is_liuhe($this->bazi[8], $y_zhi)
                    )
                )
                ||
                (
                    $this->is_ygs($dazhi, $this->bazi[5], '印')
                    &&
                    (
                        $this->is_liuchong($d_zhi, $y_zhi)
                        || $this->is_liuhe($d_zhi, $y_zhi)
                    )
                )
            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '冲合印：流支冲或合本命或大运印支+10；',
                    'add' => 10
                ];
                $hunpei += 10;

            }
            // 流干合本命或大运印干+10
            if (
                (
                    $this->is_ygs($this->bazi[1], $this->bazi[5], '印')
                    && $this->is_wuhe($this->bazi[1], $y_gan)
                )
                ||
                (
                    $this->is_ygs($this->bazi[3], $this->bazi[5], '印')
                    && $this->is_wuhe($this->bazi[3], $y_gan)
                )
                ||
                (
                    $this->is_ygs($this->bazi[7], $this->bazi[5], '印')
                    && $this->is_wuhe($this->bazi[7], $y_gan)
                )
                ||
                (
                    $this->is_ygs($d_gan, $this->bazi[5], '印')
                    && $this->is_wuhe($d_gan, $y_gan)
                )
            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '流干合本命或大运印干+10',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            // 3、   破比劫：
            //  男命原局“争财”，流年干为食伤，地支为本气财星+13，若此时流支与日支合拱，则+7；
            //  女命原局“争官”，流年干为财星，地支为本气官杀+13，若此时流支与日支合拱，则+7
            if ($this->is_zc_zg($this->sex, $this->bazi)) {
                if (
                    $this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[5], '食伤')
                    && $this->is_ygs($liuzhi, $this->bazi[5], '财')
                ) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '男命原局“争财”，流年干为食伤，地支为本气财星',
                        'add' => 13
                    ];
                    $hunpei += 13;

                    if ($this->is_liuhe($y_zhi, $this->bazi[6])
                        || $this->is_gong($y_zhi, $this->bazi[6])) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '男命原局“争财”，流年干为食伤，地支为本气财星，若此时流支与日支合拱',
                            'add' => 7
                        ];
                        $hunpei += 7;
                    }
                } elseif ($this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[5], '财')
                    && $this->is_ygs($liuzhi, $this->bazi[5], '官杀')) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '女命原局“争官”，流年干为财星，地支为本气官杀',
                        'add' => 7
                    ];
                    $hunpei += 13;

                    if ($this->is_liuhe($y_zhi, $this->bazi[6])
                        || $this->is_gong($y_zhi, $this->bazi[6])) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '女命原局“争官”，流年干为财星，地支为本气官杀,若此时流支与日支合拱',
                            'add' => 7
                        ];
                        $hunpei += 7;
                    }
                }
            }
            // 4、   破伤官：女命日坐伤官，流支为本气印星与日支冲合拱+10；女命天干伤官，流干为财或印+10
            if ($this->sex == 2) {
                if (
                    $this->is_ygs($rizhi, $this->bazi[5], '伤官')
                    && $this->is_ygs($liuzhi, $this->bazi[5], '印')
                    && (
                        $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuhe($y_zhi, $this->bazi[6])
                        || $this->is_gong($y_zhi, $this->bazi[6])
                    )
                ) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破伤官：女命日坐伤官，流支为本气印星与日支冲合拱',
                        'add' => 10
                    ];
                    $hunpei += 10;
                }
                if (
                    (
                        $this->is_ygs($this->bazi[1], $this->bazi[5], '伤官')
                        || $this->is_ygs($this->bazi[3], $this->bazi[5], '伤官')
                        || $this->is_ygs($this->bazi[7], $this->bazi[5], '伤官')
                    )
                    &&
                    (
                        $this->is_ygs($y_gan, $this->bazi[5], '财')
                        || $this->is_ygs($y_gan, $this->bazi[5], '印')
                    )
                ) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破伤官：女命天干伤官，流干为财或印',
                        'add' => 10
                    ];
                    $hunpei += 10;
                }
            }
            // 5、   破穿：若原局日支与它支相害，流支与日支相冲或相合+10
            if (
                (
                    $this->is_liuhai($this->bazi[2], $this->bazi[6])
                    || $this->is_liuhai($this->bazi[4], $this->bazi[6])
                    || $this->is_liuhai($this->bazi[8], $this->bazi[6])
                )
                &&
                (
                    $this->is_liuchong($y_zhi, $this->bazi[6])
                    || $this->is_liuhe($y_zhi, $this->bazi[6])
                )
            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '破穿：若原局日支与它支相害，流支与日支相冲或相合',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            // 6、   破冲：若原局日支与它支相冲，流支与日支相合+10，与日支相害+7，与日支相拱+5
            if (
            (
                $this->is_liuchong($this->bazi[2], $this->bazi[6])
                || $this->is_liuchong($this->bazi[4], $this->bazi[6])
                || $this->is_liuchong($this->bazi[8], $this->bazi[6])
            )
            ) {
                if ($this->is_liuhe($y_zhi, $this->bazi[6])) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破冲：若原局日支与它支相冲，流支与日支相合',
                        'add' => 10
                    ];
                    $hunpei += 10;
                }
                if ($this->is_liuhai($y_zhi, $this->bazi[6])) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破冲：若原局日支与它支相冲，流支与日支相害',
                        'add' => 7
                    ];
                    $hunpei += 7;
                }
                if ($this->is_gong($y_zhi, $this->bazi[6])) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破冲：若原局日支与它支相冲，流支与日支相拱',
                        'add' => 5
                    ];
                    $hunpei += 5;
                }

            }
            // 7、   破合：若原局日支与它支相合，流支与日支相冲+10
            if (
                (
                    $this->is_liuhe($this->bazi[2], $this->bazi[6])
                    || $this->is_liuhe($this->bazi[4], $this->bazi[6])
                    || $this->is_liuhe($this->bazi[8], $this->bazi[6])
                )
                && $this->is_liuchong($y_zhi, $this->bazi[6])
            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '破合：若原局日支与它支相合，流支与日支相冲',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            // 8、   破墓：若本命日支为辰戌丑未，且不见刑冲，流支刑冲日支+7，若此时天干是财（男命）官杀（女命），+8
            if (in_array($this->bazi[6], ['辰', '戌', '丑', '未'])) {
                if (
                    !$this->is_xing($this->bazi[2], $this->bazi[6])
                    && !$this->is_xing($this->bazi[4], $this->bazi[6])
                    && !$this->is_xing($this->bazi[8], $this->bazi[6])
                    && !$this->is_liuchong($this->bazi[2], $this->bazi[6])
                    && !$this->is_liuchong($this->bazi[4], $this->bazi[6])
                    && !$this->is_liuchong($this->bazi[8], $this->bazi[6])
                    &&
                    (
                        $this->is_xing($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                    )
                ) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破墓：若本命日支为辰戌丑未，且不见刑冲，流支刑冲日支',
                        'add' => 7
                    ];
                    $hunpei += 7;

                    if (
                        (
                            $this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[5], '财')
                        )
                        ||
                        (
                            $this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[5], '官杀')
                        )
                    ) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '破墓：若本命日支为辰戌丑未，且不见刑冲，流支刑冲日支,若此时天干是财（男命）官杀（女命）',
                            'add' => 8
                        ];
                        $hunpei += 8;
                    }
                }
            }
            // 9、   财官入宫：
            // 男命流干财星，流支为日支+15，流支与日支合+14，流支与日支拱+10，流支与原局财星相合或相拱+10；
            // 女命流干官杀，流支为日支+15，流支与日支合+14，流支与日支拱+10，流支与原局官杀相合或相拱+10
            // 【日支可用本命比肩坐支代替，如果本命天干有比肩的话】
            // 日支 + 本命比肩坐支
            $rz = [$this->bazi[6]];
            if ($this->shishen[$this->bazi[1]][$this->bazi[5]] == '比肩'
                && $this->bazi[2] != $this->bazi[6])
                $rz[] = $this->bazi[2];
            if ($this->shishen[$this->bazi[3]][$this->bazi[5]] == '比肩'
                && $this->bazi[4] != $this->bazi[6])
                $rz[] = $this->bazi[4];
            if ($this->shishen[$this->bazi[7]][$this->bazi[5]] == '比肩'
                && $this->bazi[8] != $this->bazi[6])
                $rz[] = $this->bazi[8];
            if ($this->sex == 1 || $this->sex == 2) {
                if (
                    ($this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[5], '财'))
                    || ($this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[5], '官杀'))
                ) {
                    foreach ($rz as $z) {
                        if ($y_zhi == $z) {
                            $ret['hunpei'][$num]['condition'][] = [
                                'if' => '财官入宫：男命流干财星/女命流干官杀，流支为日支',
                                'add' => 15
                            ];
                            $hunpei += 15;
                        } elseif ($this->is_liuhe($y_zhi, $z)) {
                            $ret['hunpei'][$num]['condition'][] = [
                                'if' => '财官入宫：男命流干财星/女命流干官杀，流支合日支',
                                'add' => 14
                            ];
                            $hunpei += 14;
                        } elseif ($this->is_gong($y_zhi, $z)) {
                            $ret['hunpei'][$num]['condition'][] = [
                                'if' => '财官入宫：男命流干财星/女命流干官杀，流支拱日支',
                                'add' => 10
                            ];
                            $hunpei += 10;
                        }
                    }
                    if (
                        (
                            (
                                $this->sex == 1
                                && $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '财')
                            )
                            ||
                            (
                                $this->sex == 2
                                && $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '官杀')
                            )
                        )
                        &&
                        (
                            $this->is_liuhe($y_zhi, $this->bazi[2])
                            || $this->is_gong($y_zhi, $this->bazi[2])
                        )
                    ) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '财官入宫：男命流干财星/女命流干官杀，流支与原局【2】财星相合或相拱',
                            'add' => 10
                        ];
                        $hunpei += 10;
                    }
                    if (
                        (
                            (
                                $this->sex == 1
                                && $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '财')
                            )
                            ||
                            (
                                $this->sex == 2
                                && $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '官杀')
                            )
                        )
                        &&
                        (
                            $this->is_liuhe($y_zhi, $this->bazi[4])
                            || $this->is_gong($y_zhi, $this->bazi[4])
                        )
                    ) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '财官入宫：男命流干财星/女命流干官杀，流支与原局【4】财星相合或相拱',
                            'add' => 10
                        ];
                        $hunpei += 10;
                    }
                    if (
                        (
                            (
                                $this->sex == 1
                                && $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '财')
                            )
                            ||
                            (
                                $this->sex == 2
                                && $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '官杀')
                            )
                        )
                        &&
                        (
                            $this->is_liuhe($y_zhi, $this->bazi[6])
                            || $this->is_gong($y_zhi, $this->bazi[6])
                        )
                    ) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '财官入宫：男命流干财星/女命流干官杀，流支与原局【6】财星相合或相拱',
                            'add' => 10
                        ];
                        $hunpei += 10;
                    }
                    if (
                        (
                            (
                                $this->sex == 1
                                && $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '财')
                            )
                            ||
                            (
                                $this->sex == 2
                                && $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '官杀')
                            )
                        )
                        &&
                        (
                            $this->is_liuhe($y_zhi, $this->bazi[8])
                            || $this->is_gong($y_zhi, $this->bazi[8])
                        )
                    ) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '财官入宫：男命流干财星/女命流干官杀，流支与原局【8】财星相合或相拱',
                            'add' => 10
                        ];
                        $hunpei += 10;
                    }
                }
            }
            // 10、  财官入宫二：
            // 男命运干或本命天干有财星，流干来合该财星，流支=日支（或本命比肩坐支）；
            // 女命运干或本命天干有官杀，流干来合该官星，流支=日支（或本命比肩坐支）
            $liuzhi_rizhi = false;
            foreach ($rz as $z) {
                if ($y_zhi == $z) $liuzhi_rizhi = true;
                continue;
            }
            if (
                (
                    (
                        (
                            $this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[1], '财')
                            ||
                            $this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[1], '官杀')
                        )
                        && $this->is_wuhe($y_gan, $this->bazi[1])
                    )
                    ||
                    (
                        (
                            $this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[3], '财')
                            ||
                            $this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[3], '官杀')
                        )
                        && $this->is_wuhe($y_gan, $this->bazi[3])
                    )
                    ||
                    (
                        (
                            $this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[7], '财')
                            ||
                            $this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[7], '官杀')
                        )
                        && $this->is_wuhe($y_gan, $this->bazi[7])
                    )
                    ||
                    (
                        (
                            $this->sex == 1 && $this->is_ygs($y_gan, $d_gan, '财')
                            ||
                            $this->sex == 2 && $this->is_ygs($y_gan, $d_gan, '官杀')
                        )
                        && $this->is_wuhe($y_gan, $d_gan)
                    )
                )
                && $liuzhi_rizhi === true

            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '10、    财官入宫二：男命运干或本命天干有财星，流干来合该财星，流支=日支（或本命比肩坐支）；女命运干或本命天干有官杀，流干来合该官星，流支=日支（或本命比肩坐支）',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            // 11、  财官入宫三：
            //  男命运干为财星，流支是日支或合拱日支+10；
            //  女命运干为官杀，流支是日支或合拱日支+10
            if (
                (
                    $this->sex == 1 && $this->is_ygs($y_gan, $d_gan, '财')
                    ||
                    $this->sex == 2 && $this->is_ygs($y_gan, $d_gan, '官杀')
                )
                &&
                (
                    $liuzhi_rizhi === true
                    || $this->is_liuhe($y_zhi, $this->bazi[6])
                    || $this->is_gong($y_zhi, $this->bazi[6])
                )
            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '财官入宫三：男命运干为财星，流支是日支或合拱日支；女命运干为官杀，流支是日支或合拱日支',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            $ret['hunpei'][$num]['taohua_score'] = $taohua;
            $ret['hunpei'][$num]['score'] = $hunpei;


            $ret['qingbian'][$num]['year'] = $j;
            $ret['qingbian'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['qingbian'][$num]['dayun_gan'] = $d_gan;
//            $ret['qingbian'][$num]['dayun_zhi'] = $d_zhi;
            $ret['qingbian'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['qingbian'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['qingbian'][$num]['liunian_gan'] = $y_gan;
//            $ret['qingbian'][$num]['liunian_zhi'] = $y_zhi;
            $ret['qingbian'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['qingbian'][$num]['liunian_zhiqi'] = $liuzhi;

            $qingbian = 0;
            // 1、合穿：流年与本命日柱支穿+5，
            //  若此时流干合日干+8，女命流干正官或男命流干正财+5，
            //  女命流支本气官杀或男命流支本气财星+5，女命流干官杀或男命流干财星+5，
            //  原局或运支有流支+5
            if ($this->is_liuhai($y_zhi, $this->bazi[6])) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '合穿：流年与本命日柱支穿',
                    'add' => 5
                ];
                $qingbian += 5;
                if ($this->is_wuhe($y_gan, $this->bazi[5])) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支穿,若此时流干合日干',
                        'add' => 8
                    ];
                    $qingbian += 8;
                }
                if (
                    ($this->sex == 1 && $this->shishen[$y_gan][$this->bazi[5]] == '正财')
                    || ($this->sex == 2 && $this->shishen[$y_gan][$this->bazi[5]] == '正官')
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支穿,女命流干正官或男命流干正财',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    ($this->sex == 1 && $this->is_ygs($liuzhi, $this->bazi[5], '财'))
                    || ($this->sex == 2 && $this->is_ygs($liuzhi, $this->bazi[5], '官杀'))
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支穿,女命流支本气官杀或男命流支本气财星',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    ($this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[5], '财'))
                    || ($this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[5], '官杀'))
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支穿,女命流干官杀或男命流干财星',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    $this->bazi[2] == $y_zhi
                    || $this->bazi[4] == $y_zhi
                    || $this->bazi[6] == $y_zhi
                    || $this->bazi[7] == $y_zhi
                    || $d_zhi == $y_zhi
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支穿,原局或运支有流支',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
            }
            // 2、合刑：流年与本命日柱支刑+5，
            //  若此时流干合日干+8，女命流干正官或男命流干正财+5，
            //  女命流支本气官杀或男命流支本气财星+5，
            //  原局或运支有流支+5，原局或运支有日支的冲支+5。
            if ($this->is_xing($y_zhi, $this->bazi[6])) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '合穿：流年与本命日柱支刑',
                    'add' => 5
                ];
                $qingbian += 5;
                if ($this->is_wuhe($y_gan, $this->bazi[5])) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支刑,若此时流干合日干',
                        'add' => 8
                    ];
                    $qingbian += 8;
                }
                if (
                    ($this->sex == 1 && $this->shishen[$y_gan][$this->bazi[5]] == '正财')
                    || ($this->sex == 2 && $this->shishen[$y_gan][$this->bazi[5]] == '正官')
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支刑,女命流干正官或男命流干正财',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    ($this->sex == 1 && $this->is_ygs($liuzhi, $this->bazi[5], '财'))
                    || ($this->sex == 2 && $this->is_ygs($liuzhi, $this->bazi[5], '官杀'))
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支刑,女命流支本气官杀或男命流支本气财星',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    $this->bazi[2] == $y_zhi
                    || $this->bazi[4] == $y_zhi
                    || $this->bazi[6] == $y_zhi
                    || $this->bazi[7] == $y_zhi
                    || $d_zhi == $y_zhi
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支刑,原局或运支有流支',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    $this->is_liuchong($this->bazi[2], $this->bazi[6])
                    || $this->is_liuchong($this->bazi[4], $this->bazi[6])
                    || $this->is_liuchong($this->bazi[8], $this->bazi[6])
                    || $this->is_liuchong($d_zhi, $this->bazi[6])
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支刑,原局或运支有日支的冲支',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
            }
            // 3、穿财（男）：流支与本命大运财支相害||流支害本命大运财星坐支||流干为财且流支害本命大运日支外的某支+6，若此时流干与穿柱之干或日干相合，+5，
            if ($this->sex == 1) {
                $cg = '财';
            } // 4、穿官杀（女）：流支与本命大运官杀支相害||流支害本命大运官杀坐支||流干为官杀且流支害本命大运日支外的某支+6，若此时流干与穿柱之干或日干相合，+5，
            elseif ($this->sex == 2) {
                $cg = '官杀';
            }
            if (
                (
                    ($this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[2]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[4]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[6]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[8]))
                    ||
                    ($this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $d_zhi))
                )
                ||
                (
                    ($this->is_ygs($this->bazi[1], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[2]))
                    ||
                    ($this->is_ygs($this->bazi[3], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[4]))
                    ||
                    ($this->is_ygs($this->bazi[7], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[8]))
                    ||
                    ($this->is_ygs($d_gan, $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $d_zhi))
                )
                ||
                (
                    $this->is_ygs($d_gan, $this->bazi[5], $cg)
                    &&
                    (
                        ($this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                            && $this->is_liuhai($y_zhi, $this->bazi[2]))
                        ||
                        ($this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                            && $this->is_liuhai($y_zhi, $this->bazi[4]))
                        ||
                        ($this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                            && $this->is_liuhai($y_zhi, $this->bazi[8]))
                        ||
                        ($this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                            && $this->is_liuhai($y_zhi, $d_zhi))
                    )
                )
            ) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '流支与本命大运财支相害||流支害本命大运财星坐支||流干为财且流支害本命大运日支外的某支',
                    'add' => 6
                ];
                $qingbian += 6;
                if (
                    $this->is_wuhe($y_gan, $this->bazi[5])
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[2])
                        && $this->is_wuhe($y_gan, $this->bazi[1])
                    )
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[4])
                        && $this->is_wuhe($y_gan, $this->bazi[3])
                    )
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[8])
                        && $this->is_wuhe($y_gan, $this->bazi[7])
                    )
                    || (
                        $this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $d_zhi)
                        && $this->is_wuhe($y_gan, $d_gan)
                    )
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '流支与本命大运财支相害||流支害本命大运财星坐支||流干为财且流支害本命大运日支外的某支,若此时流干与穿柱之干或日干相合',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
            }
            // 5、刑财官：【参考3/4两条，将穿害替换为刑】
            if (
                (
                    ($this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[2]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[4]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[6]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[8]))
                    ||
                    ($this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $d_zhi))
                )
                ||
                (
                    ($this->is_ygs($this->bazi[1], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[2]))
                    ||
                    ($this->is_ygs($this->bazi[3], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[4]))
                    ||
                    ($this->is_ygs($this->bazi[7], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[8]))
                    ||
                    ($this->is_ygs($d_gan, $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $d_zhi))
                )
                ||
                (
                    $this->is_ygs($d_gan, $this->bazi[5], $cg)
                    &&
                    (
                        ($this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                            && $this->is_xing($y_zhi, $this->bazi[2]))
                        ||
                        ($this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                            && $this->is_xing($y_zhi, $this->bazi[4]))
                        ||
                        ($this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                            && $this->is_xing($y_zhi, $this->bazi[8]))
                        ||
                        ($this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                            && $this->is_xing($y_zhi, $d_zhi))
                    )
                )
            ) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '流支与本命大运财支相刑||流支害本命大运财星坐支||流干为财且流支害本命大运日支外的某支',
                    'add' => 6
                ];
                $qingbian += 6;
                if (
                    $this->is_wuhe($y_gan, $this->bazi[5])
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[2])
                        && $this->is_wuhe($y_gan, $this->bazi[1])
                    )
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[4])
                        && $this->is_wuhe($y_gan, $this->bazi[3])
                    )
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[8])
                        && $this->is_wuhe($y_gan, $this->bazi[7])
                    )
                    || (
                        $this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $d_zhi)
                        && $this->is_wuhe($y_gan, $d_gan)
                    )
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '流支与本命大运财支相刑||流支害本命大运财星坐支||流干为财且流支害本命大运日支外的某支,若此时流干与穿柱之干或日干相合',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
            }
            // 6、劫伤：
            //  男命流干为劫财+5，此时流支本气比肩劫财+4；
            //  女命流干为伤官+5，此时流支本气为食神伤官+4
            if ($this->sex == 1 && $this->shishen[$y_gan][$this->bazi[5]] == '劫财') {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '男命流干为劫财',
                    'add' => 5
                ];
                $qingbian += 5;
                if ($this->is_ygs($liuzhi, $this->bazi[5], '比劫')) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '男命流干为劫财，此时流支本气比肩劫财',
                        'add' => 4
                    ];
                    $qingbian += 4;
                }
            } elseif ($this->sex == 2 && $this->shishen[$y_gan][$this->bazi[5]] == '伤官') {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '女命流干为伤官',
                    'add' => 5
                ];
                $qingbian += 5;
                if ($this->is_ygs($liuzhi, $this->bazi[5], '食伤')) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '女命流干为伤官，此时流支本气为食神伤官',
                        'add' => 5
                    ];
                    $qingbian += 4;
                }
            }
            // 7、反吟：流干比肩，日支与流支冲，+7，若此时流支与运支冲，+6
            if ($this->shishen[$y_gan][$this->bazi[5]] == '比肩'
                && $this->is_liuchong($this->bazi[6], $y_zhi)) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '流干比肩，日支与流支冲',
                    'add' => 7
                ];
                $qingbian += 7;
                if ($this->is_liuchong($d_zhi, $y_zhi)) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '流干比肩，日支与流支冲，若此时流支与运支冲',
                        'add' => 6
                    ];
                    $qingbian += 6;
                }
            }
            // 8、伏吟1：日支在本命中受刑穿，或日支在本命中受冲且日支为夫妻星（男命财星女命官杀），此时流干比肩且流支为日支+12
            if (
                (
                    $this->is_xing($this->bazi[6], $this->bazi[2])
                    || $this->is_liuhai($this->bazi[6], $this->bazi[2])
                    || $this->is_xing($this->bazi[6], $this->bazi[4])
                    || $this->is_liuhai($this->bazi[6], $this->bazi[4])
                    || $this->is_xing($this->bazi[6], $this->bazi[8])
                    || $this->is_liuhai($this->bazi[6], $this->bazi[8])
                )
                ||
                (
                    $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], $cg)
                    &&
                    (
                        $this->is_liuchong($this->bazi[6], $this->bazi[2])
                        || $this->is_liuchong($this->bazi[6], $this->bazi[4])
                        || $this->is_liuchong($this->bazi[6], $this->bazi[8])
                    )
                )
            ) {
                if (
                    $this->shishen[$y_gan][$this->bazi[5]] == '比肩'
                    && $y_zhi == $this->bazi[6]
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '日支在本命中受刑穿，或日支在本命中受冲且日支为夫妻星（男命财星女命官杀），此时流干比肩且流支为日支',
                        'add' => 12
                    ];
                    $qingbian += 12;
                }
            }
            // 9、伏吟2：日支受大运刑穿，或日支受运支冲且日支为夫妻星（男命财星女命官杀），此时流干比肩且流支为日支+12
            if (
                (
                    $this->is_xing($this->bazi[6], $d_zhi)
                    || $this->is_liuhai($this->bazi[6], $d_zhi)
                )
                ||
                (
                    $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], $cg)
                    && $this->is_liuchong($this->bazi[6], $d_zhi)
                )
            ) {
                if (
                    $this->shishen[$y_gan][$this->bazi[5]] == '比肩'
                    && $y_zhi == $this->bazi[6]
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '日支受大运刑穿，或日支受运支冲且日支为夫妻星（男命财星女命官杀），此时流干比肩且流支为日支',
                        'add' => 12
                    ];
                    $qingbian += 12;
                }
            }
            // 10、夺财官：本命天干有官杀（女）或财（男）被 本命或大运 日干外的天干所合，流年遇到该天干+10
            if (
                (
                    $this->is_ygs($this->bazi[1], $this->bazi[5], $cg)
                    &&
                    (
                        (
                            $this->is_wuhe($this->bazi[1], $this->bazi[3])
                            && $y_gan == $this->bazi[3]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[1], $this->bazi[7])
                            && $y_gan == $this->bazi[7]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[1], $d_gan)
                            && $y_gan == $d_gan
                        )
                    )
                )
                ||
                (
                    $this->is_ygs($this->bazi[3], $this->bazi[5], $cg)
                    &&
                    (
                        (
                            $this->is_wuhe($this->bazi[3], $this->bazi[1])
                            && $y_gan == $this->bazi[1]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[3], $this->bazi[7])
                            && $y_gan == $this->bazi[7]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[3], $d_gan)
                            && $y_gan == $d_gan
                        )
                    )
                )
                ||
                (
                    $this->is_ygs($this->bazi[7], $this->bazi[5], $cg)
                    &&
                    (
                        (
                            $this->is_wuhe($this->bazi[7], $this->bazi[1])
                            && $y_gan == $this->bazi[1]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[7], $this->bazi[3])
                            && $y_gan == $this->bazi[3]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[3], $d_gan)
                            && $y_gan == $d_gan
                        )
                    )
                )
            ) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '本命天干有官杀（女）或财（男）被 本命或大运 日干外的天干所合，流年遇到该天干',
                    'add' => 10
                ];
                $qingbian += 10;
            }
            $ret['qingbian'][$num]['score'] = $qingbian;


            $ret['zhuanbian'][$num]['year'] = $j;
            $ret['zhuanbian'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['zhuanbian'][$num]['dayun_gan'] = $d_gan;
//            $ret['zhuanbian'][$num]['dayun_zhi'] = $d_zhi;
            $ret['zhuanbian'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['zhuanbian'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['zhuanbian'][$num]['liunian_gan'] = $y_gan;
//            $ret['zhuanbian'][$num]['liunian_zhi'] = $y_zhi;
            $ret['zhuanbian'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['zhuanbian'][$num]['liunian_zhiqi'] = $liuzhi;

            $zhuanbian = 0;

            // 1、正冲：流干比肩，且流支与本命或大运某支相冲，+10；
            if (
                $this->shishen[$y_gan][$this->bazi[5]] == '比肩'
                &&
                (
                    $this->is_liuchong($y_zhi, $this->bazi[2])
                    || $this->is_liuchong($y_zhi, $this->bazi[4])
                    || $this->is_liuchong($y_zhi, $this->bazi[6])
                    || $this->is_liuchong($y_zhi, $this->bazi[8])
                    || $this->is_liuchong($y_zhi, $d_zhi)
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '正冲：流干比肩，且流支与本命或大运某支相冲',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 2、冲日：流支与日支相冲+10
            if ($this->is_liuchong($y_zhi, $this->bazi[6])) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '冲日：流支与日支相冲',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 3、冲禄：本命或大运有日干之禄，流支冲该禄，+10；
            if (
                (
                    $this->is_lushen($this->bazi[5], $this->bazi[2])
                    && $this->is_liuchong($y_zhi, $this->bazi[2])
                )
                ||
                (
                    $this->is_lushen($this->bazi[5], $this->bazi[4])
                    && $this->is_liuchong($y_zhi, $this->bazi[4])
                )
                ||
                (
                    $this->is_lushen($this->bazi[5], $this->bazi[6])
                    && $this->is_liuchong($y_zhi, $this->bazi[6])
                )
                ||
                (
                    $this->is_lushen($this->bazi[5], $this->bazi[8])
                    && $this->is_liuchong($y_zhi, $this->bazi[8])
                )
                ||
                (
                    $this->is_lushen($this->bazi[5], $d_zhi)
                    && $this->is_liuchong($y_zhi, $d_zhi)
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '冲禄：本命或大运有日干之禄，流支冲该禄',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 4、冲比肩坐支：若本命或大运有比肩，流支冲比肩坐支，+5
            if (
                (
                    $this->shishen[$this->bazi[1]][$this->bazi[5]] == '比肩'
                    && $this->is_liuchong($y_zhi, $this->bazi[2])
                )
                ||
                (
                    $this->shishen[$this->bazi[3]][$this->bazi[5]] == '比肩'
                    && $this->is_liuchong($y_zhi, $this->bazi[4])
                )
                ||
                (
                    $this->shishen[$this->bazi[7]][$this->bazi[5]] == '比肩'
                    && $this->is_liuchong($y_zhi, $this->bazi[8])
                )
                ||
                (
                    $this->shishen[$d_gan][$this->bazi[5]] == '比肩'
                    && $this->is_liuchong($y_zhi, $d_zhi)
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '冲比肩坐支：若本命或大运有比肩，流支冲比肩坐支',
                    'add' => 5
                ];
                $zhuanbian += 5;
            }
            // 5、双冲：流年与日柱或大运天克(五行相克【七杀||正财】)地冲+15，与月柱或时柱天克地冲+10
            if (
                (
                    in_array($this->shishen[$y_gan][$this->bazi[5]], ['正财', '七杀'])
                    && $this->is_liuchong($y_zhi, $this->bazi[6])
                )
                ||
                (
                    in_array($this->shishen[$y_gan][$d_gan], ['正财', '七杀'])
                    && $this->is_liuchong($y_zhi, $d_zhi)
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '双冲：流年与日柱或大运天克(五行相克【七杀||正财】)地冲',
                    'add' => 15
                ];
                $zhuanbian += 15;
            }
            if (
                (
                    in_array($this->shishen[$y_gan][$this->bazi[3]], ['正财', '七杀'])
                    && $this->is_liuchong($y_zhi, $this->bazi[4])
                )
                ||
                (
                    in_array($this->shishen[$y_gan][$this->bazi[7]], ['正财', '七杀'])
                    && $this->is_liuchong($y_zhi, $this->bazi[8])
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '双冲：流年与与月柱或时柱天克地冲',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 6、引冲：原局或大运有地支相冲，流支为相冲地支中的一个，+5
            if (
                (
                    $this->is_liuchong($this->bazi[2], $this->bazi[4])
                    && in_array($y_zhi, [$this->bazi[2], $this->bazi[4]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[2], $this->bazi[6])
                    && in_array($y_zhi, [$this->bazi[2], $this->bazi[6]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[2], $this->bazi[8])
                    && in_array($y_zhi, [$this->bazi[2], $this->bazi[8]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[2], $d_zhi)
                    && in_array($y_zhi, [$this->bazi[2], $d_zhi])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[4], $this->bazi[6])
                    && in_array($y_zhi, [$this->bazi[4], $this->bazi[6]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[4], $this->bazi[8])
                    && in_array($y_zhi, [$this->bazi[4], $this->bazi[8]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[4], $d_zhi)
                    && in_array($y_zhi, [$this->bazi[4], $d_zhi])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[6], $this->bazi[8])
                    && in_array($y_zhi, [$this->bazi[6], $this->bazi[8]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[6], $d_zhi)
                    && in_array($y_zhi, [$this->bazi[6], $d_zhi])
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '引冲：原局或大运有地支相冲，流支为相冲地支中的一个',
                    'add' => 5
                ];
                $zhuanbian += 5;
            }
            // 7、引刑：原局或大运有地支凑齐三刑，流支来冲其中之一+10
            if (
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[4], $this->bazi[6])
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[4], $this->bazi[8])
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[6], $this->bazi[8])
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[4], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[6], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[8], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[4], $this->bazi[6], $this->bazi[8])
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[4], $this->bazi[6], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[4], $this->bazi[8], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[6], $this->bazi[8], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '引刑：原局或大运有地支凑齐三刑，流支来冲其中之一',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 8、运冲：原局某柱与大运干支形成正冲或双冲（正冲：天干一致，地支相冲；双冲：天干相克地支相冲），此时流支与该组相冲地支之一形成合、冲、拱、刑，+10
            if (
                (
                    (
                        $this->bazi[1] == $d_gan
                        || in_array($this->shishen[$this->bazi[1]][$d_gan], ['七杀', '正财'])
                    )
                    && $this->is_liuchong($this->bazi[2], $d_zhi)
                    &&
                    (
                        $this->is_liuhe($this->bazi[2], $y_zhi)
                        || $this->is_liuhe($d_zhi, $y_zhi)
                        || $this->is_liuchong($this->bazi[2], $y_zhi)
                        || $this->is_liuchong($d_zhi, $y_zhi)
                        || $this->is_gong($this->bazi[2], $y_zhi)
                        || $this->is_gong($d_zhi, $y_zhi)
                        || $this->is_xing($this->bazi[2], $y_zhi)
                        || $this->is_xing($d_zhi, $y_zhi)
                    )
                )
                ||
                (
                    (
                        $this->bazi[3] == $d_gan
                        || in_array($this->shishen[$this->bazi[3]][$d_gan], ['七杀', '正财'])
                    )
                    && $this->is_liuchong($this->bazi[4], $d_zhi)
                    &&
                    (
                        $this->is_liuhe($this->bazi[4], $y_zhi)
                        || $this->is_liuhe($d_zhi, $y_zhi)
                        || $this->is_liuchong($this->bazi[4], $y_zhi)
                        || $this->is_liuchong($d_zhi, $y_zhi)
                        || $this->is_gong($this->bazi[4], $y_zhi)
                        || $this->is_gong($d_zhi, $y_zhi)
                        || $this->is_xing($this->bazi[4], $y_zhi)
                        || $this->is_xing($d_zhi, $y_zhi)
                    )
                )
                ||
                (
                    (
                        $this->bazi[5] == $d_gan
                        || in_array($this->shishen[$this->bazi[5]][$d_gan], ['七杀', '正财'])
                    )
                    && $this->is_liuchong($this->bazi[6], $d_zhi)
                    &&
                    (
                        $this->is_liuhe($this->bazi[6], $y_zhi)
                        || $this->is_liuhe($d_zhi, $y_zhi)
                        || $this->is_liuchong($this->bazi[6], $y_zhi)
                        || $this->is_liuchong($d_zhi, $y_zhi)
                        || $this->is_gong($this->bazi[6], $y_zhi)
                        || $this->is_gong($d_zhi, $y_zhi)
                        || $this->is_xing($this->bazi[6], $y_zhi)
                        || $this->is_xing($d_zhi, $y_zhi)
                    )
                )
                ||
                (
                    (
                        $this->bazi[7] == $d_gan
                        || in_array($this->shishen[$this->bazi[7]][$d_gan], ['七杀', '正财'])
                    )
                    && $this->is_liuchong($this->bazi[8], $d_zhi)
                    &&
                    (
                        $this->is_liuhe($this->bazi[8], $y_zhi)
                        || $this->is_liuhe($d_zhi, $y_zhi)
                        || $this->is_liuchong($this->bazi[8], $y_zhi)
                        || $this->is_liuchong($d_zhi, $y_zhi)
                        || $this->is_gong($this->bazi[8], $y_zhi)
                        || $this->is_gong($d_zhi, $y_zhi)
                        || $this->is_xing($this->bazi[8], $y_zhi)
                        || $this->is_xing($d_zhi, $y_zhi)
                    )
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '运冲：原局某柱与大运干支形成正冲或双冲（正冲：天干一致，地支相冲；双冲：天干相克地支相冲），此时流支与该组相冲地支之一形成合、冲、拱、刑',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 9、星盘补充：三限天王星刑冲合太阳+10，此时若木星与太阳成相+5；三限天王星六分三分太阳+5；行运天王星合四轴或刑冲合月亮+5
            $time_4_1 = $j . "-4-1";
            $time_10_1 = $j . "-10-1";
            $Third = new ThirdprogressedController();
            $Third->recode = $this->userinfo;
            $th_4_1 = json_decode($Third->get($time_4_1), true)['data']['planets'];
            $th_10_1 = json_decode($Third->get($time_10_1), true)['data']['planets'];
            $Transits = new TransitsController();
            $Transits->recode = $this->userinfo;
            $tr_4_1 = json_decode($Transits->get($time_4_1), true)['data'][1]['planets'];
            $tr_10_1 = json_decode($Transits->get($time_10_1), true)['data'][1]['planets'];
            $score_4_1 = 0;
            $score_10_1 = 0;
            if (isset($th_4_1[0]['phase']['0-7'])) {
                if (in_array($th_4_1[0]['phase']['0-7']['phase_e'], [0, 90, 180])) {
                    $score_4_1 += 10;
                    if (isset($th_4_1[0]['phase']['0-5'])) {
                        $score_4_1 += 5;
                    }
                } elseif (in_array($th_4_1[0]['phase']['0-7']['phase_e'], [60, 120])) {
                    $score_4_1 += 5;
                }

            }
            if (
                (
                    isset($tr_4_1[7]['phase']['7-' . ASC])
                    && in_array($tr_4_1[7]['phase']['7-' . ASC]['phase_e'], [0, 180])
                )
                ||
                (
                    isset($tr_4_1[7]['phase']['7-' . MC])
                    && in_array($tr_4_1[7]['phase']['7-' . MC]['phase_e'], [0, 180])
                )
                ||
                (
                    isset($tr_4_1[7]['phase']['7-1'])
                    && in_array($tr_4_1[7]['phase']['7-1']['phase_e'], [0, 90, 180])
                )
            ) {
                $score_4_1 += 5;
            }
            if (isset($th_10_1[0]['phase']['0-7'])) {
                if (in_array($th_10_1[0]['phase']['0-7']['phase_e'], [0, 90, 180])) {
                    $score_10_1 += 10;
                    if (isset($th_10_1[0]['phase']['0-5'])) {
                        $score_10_1 += 5;
                    }
                } elseif (in_array($th_10_1[0]['phase']['0-7']['phase_e'], [60, 120])) {
                    $score_10_1 += 5;
                }

            }
            if (
                (
                    isset($tr_10_1[7]['phase']['7-' . ASC])
                    && in_array($tr_10_1[7]['phase']['7-' . ASC]['phase_e'], [0, 180])
                )
                ||
                (
                    isset($tr_10_1[7]['phase']['7-' . MC])
                    && in_array($tr_10_1[7]['phase']['7-' . MC]['phase_e'], [0, 180])
                )
                ||
                (
                    isset($tr_10_1[7]['phase']['7-1'])
                    && in_array($tr_10_1[7]['phase']['7-1']['phase_e'], [0, 90, 180])
                )
            ) {
                $score_10_1 += 5;
            }
            if ($score_4_1 > $score_10_1) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '4月-1日',
                    'add' => 10
                ];
                $zhuanbian += $score_4_1;
            } elseif ($score_4_1 < $score_10_1) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '10月1日',
                    'add' => 10
                ];
                $zhuanbian += $score_10_1;
            }

            $ret['zhuanbian'][$num]['score'] = $zhuanbian;

            $ret['shengzhi'][$num]['year'] = $j;
            $ret['shengzhi'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['shengzhi'][$num]['dayun_gan'] = $d_gan;
//            $ret['shengzhi'][$num]['dayun_zhi'] = $d_zhi;
            $ret['shengzhi'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['shengzhi'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['shengzhi'][$num]['liunian_gan'] = $y_gan;
//            $ret['shengzhi'][$num]['liunian_zhi'] = $y_zhi;
            $ret['shengzhi'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['shengzhi'][$num]['liunian_zhiqi'] = $liuzhi;

            $shengzhi = 0;
            // 1、流干或流支出现官杀+5（地支以本气论），若此时流支=日干禄或流干=比肩+5，若此时流支与日支相合+8相拱+5，若此时流支与运命某支（非日支）相合且不刑害日支+5
            if (
                $this->is_ygs($y_gan, $this->bazi[5], '官杀')
                || $this->is_ygs($liuzhi, $this->bazi[5], '官杀')
            ) {
                $ret['shengzhi'][$num]['condition'][] = [
                    'if' => '流干或流支出现官杀',
                    'add' => 5
                ];
                $shengzhi += 5;
                if (
                    $this->is_lushen($this->bazi[5], $y_zhi)
                    || $this->bazi[5] == $y_gan
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '流干或流支出现官杀,若此时流支=日干禄或流干=比肩',
                        'add' => 5
                    ];
                    $shengzhi += 5;
                }
                if ($this->is_liuhe($y_zhi, $this->bazi[6])) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '流干或流支出现官杀,若此时流支与日支相合',
                        'add' => 8
                    ];
                    $shengzhi += 8;
                }
                if ($this->is_gong($y_zhi, $this->bazi[6])) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '流干或流支出现官杀,若此时流支与日支相拱',
                        'add' => 8
                    ];
                    $shengzhi += 8;
                }
                if (
                    !$this->is_liuhai($y_zhi, $this->bazi[6])
                    && !$this->is_xing($y_zhi, $this->bazi[6])
                    &&
                    (
                        $this->is_liuhe($y_zhi, $this->bazi[2])
                        || $this->is_liuhe($y_zhi, $this->bazi[4])
                        || $this->is_liuhe($y_zhi, $this->bazi[8])
                        || $this->is_liuhe($y_zhi, $d_zhi)
                    )
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '流干或流支出现官杀,若此时流支与运命某支（非日支）相合且不刑害日支',
                        'add' => 5
                    ];
                    $shengzhi += 5;
                }
            }

            // 2、原局天干有官杀或月支日支为官杀且官杀衰弱（低于20%）且日干助力强旺（比劫+印高于40%），流干或流支为官杀+10
            // 3、原局天干有官杀或月支日支为官杀且官杀强旺（高于20%）且日干助力衰弱（比劫+印低于40%），流干或流支为正印+10
            $wx_perc = $this->get_wuxing_percent();// 获取五行百分比
            $rigan_wx = $this->wuxing[$this->bazi[5]];// 日干五行属性
            $wx_beike = ['木' => '金', '土' => '木', '水' => '土', '火' => '水', '金' => '火'];// 五行被克关系
            $wx_ke = ['金' => '木', '木' => '土', '土' => '水', '水' => '火', '火' => '金'];// 五行克关系
            $gs_wx = $wx_beike[$rigan_wx];// 官杀五行属性 克我
            $c_wx = $wx_ke[$rigan_wx];// 财星五行属性 我克
            $bj_wx = $rigan_wx;// 比劫五行属性 同我
            $wx_beisheng = ['土' => '金', '金' => '水', '水' => '木', '木' => '火', '火' => '土'];// 五行被生关系
            $y_wx = $wx_beisheng[$rigan_wx];// 印五行属性 生我
            $gs_prec = $wx_perc[$gs_wx];// 官杀五行百分比
            $c_prec = $wx_perc[$c_wx];// 财星五行百分比
            $bj_prec = $wx_perc[$bj_wx];// 比劫五行百分比
            $y_prec = $wx_perc[$y_wx];// 印五行百分比
            if (
                $this->is_ygs($this->bazi[1], $this->bazi[5], '官杀')
                || $this->is_ygs($this->bazi[3], $this->bazi[5], '官杀')
                || $this->is_ygs($this->bazi[7], $this->bazi[5], '官杀')
                || $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '官杀')
                || $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '官杀')
            ) {
                if (
                    (
                        $this->is_ygs($y_gan, $this->bazi[5], '官杀')
                        || $this->is_ygs($liuzhi, $this->bazi[5], '官杀')
                    )
                    && $gs_prec < 20 && ($bj_prec + $y_prec) > 40
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '原局天干有官杀或月支日支为官杀且官杀衰弱（低于20%）且日干助力强旺（比劫+印高于40%），流干或流支为官杀',
                        'add' => 10
                    ];
                    $shengzhi += 10;
                }
                if (
                    (
                        $this->shishen[$y_gan][$this->bazi[5]] == '正印'
                        || $this->shishen[$liuzhi][$this->bazi[5]] == '正印'
                    )
                    && $gs_prec > 20 && ($bj_prec + $y_prec) < 40
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '原局天干有官杀或月支日支为官杀且官杀强旺（高于20%）且日干助力衰弱（比劫+印低于40%），流干或流支为正印',
                        'add' => 10
                    ];
                    $shengzhi += 10;
                }
            }
            // 4、本命天干无伤官，运干是正官，若流干非伤官非七杀，+5，若此时运支为日干禄+6，若此时运支合拱日支+6
            // 5、本命天干有伤官，运干是正官，若流干与伤官相合或流干为正印，+10，若此时运支为日干禄+6，若此时运支合拱日支+6
            if (
                (
                    $this->shishen[$this->bazi[1]][$this->bazi[5]] == '伤官'
                    || $this->shishen[$this->bazi[3]][$this->bazi[5]] == '伤官'
                    || $this->shishen[$this->bazi[7]][$this->bazi[5]] == '伤官'
                )
                && $this->shishen[$d_gan][$this->bazi[5]] == '伤官'
            ) {
                if (
                    !$this->shishen[$y_gan][$this->bazi[5]] == '伤官'
                    && !$this->shishen[$y_gan][$this->bazi[5]] == '七杀'
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '本命天干无伤官，运干是正官，若流干非伤官非七杀',
                        'add' => 5
                    ];
                    $shengzhi += 5;
                    if ($this->is_lushen($this->bazi[5], $y_zhi)) {
                        $ret['shengzhi'][$num]['condition'][] = [
                            'if' => '本命天干无伤官，运干是正官，若流干非伤官非七杀,若此时运支为日干禄',
                            'add' => 6
                        ];
                        $shengzhi += 6;
                    }
                    if (
                        $this->is_liuhe($y_zhi, $this->bazi[6])
                        || $this->is_gong($y_zhi, $this->bazi[6])
                    ) {
                        $ret['shengzhi'][$num]['condition'][] = [
                            'if' => '本命天干无伤官，运干是正官，若流干非伤官非七杀,若此时运支合拱日支',
                            'add' => 6
                        ];
                        $shengzhi += 6;
                    }
                }
                if (
                    (
                        (
                            $this->shishen[$this->bazi[1]][$this->bazi[5]] == '伤官'
                            && $this->is_wuhe($y_gan, $this->bazi[1])
                        )
                        ||
                        (
                            $this->shishen[$this->bazi[3]][$this->bazi[5]] == '伤官'
                            && $this->is_wuhe($y_gan, $this->bazi[3])
                        )
                        ||
                        (
                            $this->shishen[$this->bazi[7]][$this->bazi[5]] == '伤官'
                            && $this->is_wuhe($y_gan, $this->bazi[7])
                        )
                    )
                    || $this->shishen[$y_gan][$this->bazi[5]] == '正印'
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '本命天干有伤官，运干是正官，若流干与伤官相合或流干为正印',
                        'add' => 10
                    ];
                    $shengzhi += 10;
                    if ($this->is_lushen($this->bazi[5], $y_zhi)) {
                        $ret['shengzhi'][$num]['condition'][] = [
                            'if' => '本命天干有伤官，运干是正官，若流干与伤官相合或流干为正印,若此时运支为日干禄',
                            'add' => 6
                        ];
                        $shengzhi += 6;
                    }
                    if (
                        $this->is_liuhe($y_zhi, $this->bazi[6])
                        || $this->is_gong($y_zhi, $this->bazi[6])
                    ) {
                        $ret['shengzhi'][$num]['condition'][] = [
                            'if' => '本命天干有伤官，运干是正官，若流干与伤官相合或流干为正印,若此时运支合拱日支',
                            'add' => 6
                        ];
                        $shengzhi += 6;
                    }
                }
            }
            // 6、若原局天干有七杀，且官杀力量大于20%，流干与七杀相合或为食神+8；若此时七杀位于运干+10
            if (
                $this->shishen[$this->bazi[1]][$this->bazi[5]] == '七杀'
                || $this->shishen[$this->bazi[3]][$this->bazi[5]] == '七杀'
                || $this->shishen[$this->bazi[7]][$this->bazi[5]] == '七杀'
            ) {
                if ($gs_prec > 20) {
                    if (
                        (
                            (
                                $this->shishen[$this->bazi[1]][$this->bazi[5]] == '七杀'
                                && $this->is_wuhe($y_gan, $this->bazi[1])
                            )
                            ||
                            (
                                $this->shishen[$this->bazi[3]][$this->bazi[5]] == '七杀'
                                && $this->is_wuhe($y_gan, $this->bazi[3])
                            )
                            ||
                            (
                                $this->shishen[$this->bazi[7]][$this->bazi[5]] == '七杀'
                                && $this->is_wuhe($y_gan, $this->bazi[7])
                            )
                        )
                        || $this->shishen[$y_gan][$this->bazi[5]] == '食神'
                    ) {
                        $ret['shengzhi'][$num]['condition'][] = [
                            'if' => '若原局天干有七杀，且官杀力量大于20%，流干与七杀相合或为食神',
                            'add' => 8
                        ];
                        $shengzhi += 8;
                        if ($this->shishen[$d_gan][$this->bazi[5]] == '七杀') {
                            $ret['shengzhi'][$num]['condition'][] = [
                                'if' => '若原局天干有七杀，且官杀力量大于20%，流干与七杀相合或为食神,若此时七杀位于运干',
                                'add' => 10
                            ];
                            $shengzhi += 10;
                        }
                    }
                }
            }
            // 7、若原局天干有正官有偏印，且财+官<印+比，流干合偏印+8
            if (
                (
                    $this->shishen[$this->bazi[1]][$this->bazi[5]] == '正官'
                    || $this->shishen[$this->bazi[3]][$this->bazi[5]] == '正官'
                    || $this->shishen[$this->bazi[7]][$this->bazi[5]] == '正官'
                )
                &&
                (
                    $this->shishen[$this->bazi[1]][$this->bazi[5]] == '偏印'
                    || $this->shishen[$this->bazi[3]][$this->bazi[5]] == '偏印'
                    || $this->shishen[$this->bazi[7]][$this->bazi[5]] == '偏印'
                )
                && ($c_prec + $gs_prec) < ($y_prec + $bj_prec)
            ) {
                if (
                    (
                        $this->shishen[$this->bazi[1]][$this->bazi[5]] == '偏印'
                        && $this->is_wuhe($this->bazi[1], $y_gan)
                    )
                    ||
                    (
                        $this->shishen[$this->bazi[3]][$this->bazi[5]] == '偏印'
                        && $this->is_wuhe($this->bazi[3], $y_gan)
                    )
                    ||
                    (
                        $this->shishen[$this->bazi[7]][$this->bazi[5]] == '偏印'
                        && $this->is_wuhe($this->bazi[7], $y_gan)
                    )
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '若原局天干有正官有偏印，且财+官<印+比，流干合偏印',
                        'add' => 8
                    ];
                    $shengzhi += 8;
                }
            }
            // 8、星盘补充：三限日木成相+6，木在10宫+4
            $time_4_1 = $j . "-4-1";
            $time_10_1 = $j . "-10-1";
            $Third = new ThirdprogressedController();
            $Third->recode = $this->userinfo;
            $th_4_1 = json_decode($Third->get($time_4_1), true)['data']['planets'];
            $th_10_1 = json_decode($Third->get($time_10_1), true)['data']['planets'];
            $score_4_1 = 0;
            $score_10_1 = 0;
            if (isset($th_4_1[0]['phase']['0-5'])) $score_4_1 += 6;
            if ($th_4_1[5]['in_house_id'] == 10) $score_4_1 += 10;
            if (isset($th_10_1[0]['phase']['0-5'])) $score_10_1 += 6;
            if ($th_10_1[5]['in_house_id'] == 10) $score_10_1 += 10;

            if ($score_4_1 > $score_10_1) {
                $ret['shengzhi'][$num]['condition'][] = [
                    'if' => '4月-1日',
                    'add' => $score_4_1
                ];
                $shengzhi += $score_4_1;
            } elseif ($score_4_1 < $score_10_1) {
                $ret['shengzhi'][$num]['condition'][] = [
                    'if' => '10月1日',
                    'add' => $score_10_1
                ];
                $shengzhi += $score_10_1;
            }
            $ret['shengzhi'][$num]['score'] = $shengzhi;

            $ret['jincai'][$num]['year'] = $j;
            $ret['jincai'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['jincai'][$num]['dayun_gan'] = $d_gan;
//            $ret['jincai'][$num]['dayun_zhi'] = $d_zhi;
            $ret['jincai'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['jincai'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['jincai'][$num]['liunian_gan'] = $y_gan;
//            $ret['jincai'][$num]['liunian_zhi'] = $y_zhi;
            $ret['jincai'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['jincai'][$num]['liunian_zhiqi'] = $liuzhi;

            $jincai = 0;

            // 1、流干或流支本气为财星+10；若此时流支=日干禄或流干=比肩+5；若此时流支=本命或大运中的财支或财干的禄+5；若此时流干=本命或大运中的财干或财支的反禄（反禄：若某地支是某天干的禄，该天干是该地支的反禄）+5
            if (
                $this->is_ygs($y_gan, $this->bazi[5], '财')
                || $this->is_ygs($liuzhi, $this->bazi[5], '财')
            ) {
                $ret['jincai'][$num]['condition'][] = [
                    'if' => '流干或流支本气为财星',
                    'add' => 10
                ];
                $jincai += 10;
                if (
                    $this->is_lushen($this->bazi[5], $y_gan)
                    || $this->bazi[5] == $y_gan
                ) {
                    $ret['jincai'][$num]['condition'][] = [
                        'if' => '流干或流支本气为财星,若此时流支=日干禄或流干=比肩',
                        'add' => 5
                    ];
                    $jincai += 5;
                }
                if (
                    (
                        $this->is_ygs($this->bazi[1], $this->bazi[5], '财')
                        && $this->is_lushen($this->bazi[1], $y_zhi)
                    )
                    ||
                    (
                        $this->is_ygs($this->bazi[3], $this->bazi[5], '财')
                        && $this->is_lushen($this->bazi[3], $y_zhi)
                    )
                    ||
                    (
                        $this->is_ygs($this->bazi[7], $this->bazi[5], '财')
                        && $this->is_lushen($this->bazi[3], $y_zhi)
                    )
                    ||
                    (
                        $this->is_ygs($d_gan, $this->bazi[5], '财')
                        && $this->is_lushen($d_gan, $y_zhi)
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '财')
                        && $y_zhi == $this->bazi[2]
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '财')
                        && $y_zhi == $this->bazi[4]
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '财')
                        && $y_zhi == $this->bazi[6]
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '财')
                        && $y_zhi == $this->bazi[8]
                    )
                ) {
                    $ret['jincai'][$num]['condition'][] = [
                        'if' => '流干或流支本气为财星,若此时流支=本命或大运中的财支或财干的禄',
                        'add' => 5
                    ];
                    $jincai += 5;
                }
                if (
                    (
                        $this->is_ygs($this->bazi[1], $this->bazi[5], '财')
                        && $this->bazi[1] == $y_gan
                    )
                    ||
                    (
                        $this->is_ygs($this->bazi[3], $this->bazi[5], '财')
                        && $this->bazi[3] == $y_gan
                    )
                    ||
                    (
                        $this->is_ygs($this->bazi[7], $this->bazi[5], '财')
                        && $this->bazi[7] == $y_gan
                    )
                    ||
                    (
                        $this->is_ygs($d_gan, $this->bazi[5], '财')
                        && $d_gan == $y_gan
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '财')
                        && $this->is_lushen($y_gan, $this->bazi[2])
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '财')
                        && $this->is_lushen($y_gan, $this->bazi[4])
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '财')
                        && $this->is_lushen($y_gan, $this->bazi[6])
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '财')
                        && $this->is_lushen($y_gan, $this->bazi[8])
                    )
                ) {
                    $ret['jincai'][$num]['condition'][] = [
                        'if' => '流干或流支本气为财星,若此时流干=本命或大运中的财干或财支的反禄（反禄：若某地支是某天干的禄，该天干是该地支的反禄）',
                        'add' => 5
                    ];
                    $jincai += 5;
                }
            }
            // 2、大运+原局天干有财星有劫财，流干合劫财或流干=正官  +10
            if (
                (
                    $this->is_ygs($this->bazi[1], $this->bazi[5], '财')
                    || $this->is_ygs($this->bazi[3], $this->bazi[5], '财')
                    || $this->is_ygs($this->bazi[7], $this->bazi[5], '财')
                    || $this->is_ygs($d_gan, $this->bazi[5], '财')
                )
                &&
                (
                    (
                        $this->shishen[$this->bazi[1]][$this->bazi[5]] == '劫财'
                        &&
                        (
                            $this->is_wuhe($y_gan, $this->bazi[1])
                            || $this->shishen[$y_gan][$this->bazi[5]] == '正官'
                        )
                    )
                    ||
                    (
                        $this->shishen[$this->bazi[3]][$this->bazi[5]] == '劫财'
                        &&
                        (
                            $this->is_wuhe($y_gan, $this->bazi[3])
                            || $this->shishen[$y_gan][$this->bazi[5]] == '正官'
                        )
                    )
                    ||
                    (
                        $this->shishen[$this->bazi[7]][$this->bazi[5]] == '劫财'
                        &&
                        (
                            $this->is_wuhe($y_gan, $this->bazi[7])
                            || $this->shishen[$y_gan][$this->bazi[5]] == '正官'
                        )
                    )
                    ||
                    (
                        $this->shishen[$d_gan][$this->bazi[5]] == '劫财'
                        &&
                        (
                            $this->is_wuhe($y_gan, $d_gan)
                            || $this->shishen[$y_gan][$this->bazi[5]] == '正官'
                        )
                    )
                )
            ) {
                $ret['jincai'][$num]['condition'][] = [
                    'if' => '大运+原局天干有财星有劫财，流干合劫财或流干=正官',
                    'add' => 10
                ];
                $jincai += 10;
            }
            // 3、大运天干为财或地支为财，若流干不是劫财且不是七杀+6
            if (
                $this->is_ygs($d_gan, $this->bazi[5], '财')
                || $this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], '财')
            ) {
                if (
                    $this->shishen[$y_gan][$this->bazi[5]] == '劫财'
                    && $this->shishen[$y_gan][$this->bazi[5]] == '七杀'
                ) {
                    $ret['jincai'][$num]['condition'][] = [
                        'if' => '大运天干为财或地支为财，若流干不是劫财且不是七杀',
                        'add' => 6
                    ];
                    $jincai += 6;
                }
            }
            // 4、星盘补充：三限日木或金木成相+6，木在2宫或土在2宫+6
            $time_4_1 = $j . "-4-1";
            $time_10_1 = $j . "-10-1";
            $Third = new ThirdprogressedController();
            $Third->recode = $this->userinfo;
            $th_4_1 = json_decode($Third->get($time_4_1), true)['data']['planets'];
            $th_10_1 = json_decode($Third->get($time_10_1), true)['data']['planets'];
            $score_4_1 = 0;
            $score_10_1 = 0;
            if (isset($th_4_1[0]['phase']['0-5']) || isset($th_4_1[3]['phase']['3-5']))
                $score_4_1 += 6;
            if ($th_4_1[5]['in_house_id'] == 2 || $th_4_1[6]['in_house_id'] == 2)
                $score_4_1 += 6;
            if (isset($th_10_1[0]['phase']['0-5']) || isset($th_10_1[3]['phase']['3-5']))
                $score_10_1 += 6;
            if ($th_10_1[5]['in_house_id'] == 2 || $th_10_1[6]['in_house_id'] == 2)
                $score_10_1 += 6;

            if ($score_4_1 > $score_10_1) {
                $ret['jincai'][$num]['condition'][] = [
                    'if' => '4月-1日',
                    'add' => $score_4_1
                ];
                $jincai += $score_4_1;
            } elseif ($score_4_1 < $score_10_1) {
                $ret['jincai'][$num]['condition'][] = [
                    'if' => '10月1日',
                    'add' => $score_10_1
                ];
                $jincai += $score_10_1;
            }
            $ret['jincai'][$num]['score'] = $jincai;

            $ret['fumu'][$num]['year'] = $j;
            $ret['fumu'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['fumu'][$num]['dayun_gan'] = $d_gan;
//            $ret['fumu'][$num]['dayun_zhi'] = $d_zhi;
            $ret['fumu'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['fumu'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['fumu'][$num]['liunian_gan'] = $y_gan;
//            $ret['fumu'][$num]['liunian_zhi'] = $y_zhi;
            $ret['fumu'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['fumu'][$num]['liunian_zhiqi'] = $liuzhi;

            $fumu = 0;
            // 1、流年地支冲本命年支+10，若此时为天克地冲+8；若此时大运天干为财星或印星+6
            if ($this->is_liuchong($y_zhi, $this->bazi[2])) {
                $ret['fumu'][$num]['condition'][] = [
                    'if' => '流年地支冲本命年支',
                    'add' => 6
                ];
                $fumu += 6;
                if (
                    in_array($this->shishen[$y_gan][$this->bazi[1]], ['正财', '七杀'])
                    && $this->is_liuchong($y_zhi, $this->bazi[2])
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流年地支冲本命年支,若此时为天克地冲',
                        'add' => 8
                    ];
                    $fumu += 8;
                }
                if (
                    $this->is_ygs($d_gan, $this->bazi[5], '财')
                    || $this->is_ygs($d_gan, $this->bazi[5], '印')
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流年地支冲本命年支,若此时大运天干为财星或印星',
                        'add' => 8
                    ];
                    $fumu += 6;
                }
            }
            // 2、流年地支刑穿本命年支+10，若此时为干合支穿+8；若此时运干为财星或印星+6
            if (
                $this->is_xing($y_zhi, $this->bazi[2])
                || $this->is_liuhai($y_zhi, $this->bazi[2])
            ) {
                $ret['fumu'][$num]['condition'][] = [
                    'if' => '流年地支刑穿本命年支',
                    'add' => 10
                ];
                $fumu += 10;
                if (
                    $this->is_wuhe($y_gan, $this->bazi[1])
                    && $this->is_liuhai($y_zhi, $this->bazi[2])
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流年地支刑穿本命年支,若此时为干合支穿',
                        'add' => 8
                    ];
                    $fumu += 8;
                }
                if (
                    $this->is_ygs($d_gan, $this->bazi[5], '财')
                    || $this->is_ygs($d_gan, $this->bazi[5], '印')
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流年地支冲本命年支,若此时大运天干为财星或印星',
                        'add' => 6
                    ];
                    $fumu += 6;
                }
            }
            // 3、流干的禄是年支，流支刑冲穿原局或大运的财支或财干坐支+14
            // 4、流干的禄是年支，流支刑冲穿原局或大运的印支或印干坐支+14
            if (
            $this->is_lushen($y_gan, $this->bazi[2])
            ) {
                if (
                    (
                        (
                            $this->is_ygs($this->bazi[1], $this->bazi[5], '财')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[2])
                            || $this->is_liuchong($y_zhi, $this->bazi[2])
                            || $this->is_liuhai($y_zhi, $this->bazi[2])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($this->bazi[3], $this->bazi[5], '财')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[4])
                            || $this->is_liuchong($y_zhi, $this->bazi[4])
                            || $this->is_liuhai($y_zhi, $this->bazi[4])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($this->bazi[7], $this->bazi[5], '财')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[8])
                            || $this->is_liuchong($y_zhi, $this->bazi[8])
                            || $this->is_liuhai($y_zhi, $this->bazi[8])
                        )
                    )
                    &&
                    (
                        $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '财')
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[6])
                            || $this->is_liuchong($y_zhi, $this->bazi[6])
                            || $this->is_liuhai($y_zhi, $this->bazi[6])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($d_gan, $this->bazi[5], '财')
                            ||
                            $this->is_ygs($dazhi, $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $d_zhi)
                            || $this->is_liuchong($y_zhi, $d_zhi)
                            || $this->is_liuhai($y_zhi, $d_zhi)
                        )
                    )
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流干的禄是年支，流支刑冲穿原局或大运的财支或财干坐支',
                        'add' => 14
                    ];
                    $fumu += 14;
                }
                if (
                    (
                        (
                            $this->is_ygs($this->bazi[1], $this->bazi[5], '印')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[2])
                            || $this->is_liuchong($y_zhi, $this->bazi[2])
                            || $this->is_liuhai($y_zhi, $this->bazi[2])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($this->bazi[3], $this->bazi[5], '印')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[4])
                            || $this->is_liuchong($y_zhi, $this->bazi[4])
                            || $this->is_liuhai($y_zhi, $this->bazi[4])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($this->bazi[7], $this->bazi[5], '印')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[8])
                            || $this->is_liuchong($y_zhi, $this->bazi[8])
                            || $this->is_liuhai($y_zhi, $this->bazi[8])
                        )
                    )
                    &&
                    (
                        $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '印')
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[6])
                            || $this->is_liuchong($y_zhi, $this->bazi[6])
                            || $this->is_liuhai($y_zhi, $this->bazi[6])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($d_gan, $this->bazi[5], '印')
                            ||
                            $this->is_ygs($dazhi, $this->bazi[5], '印')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $d_zhi)
                            || $this->is_liuchong($y_zhi, $d_zhi)
                            || $this->is_liuhai($y_zhi, $d_zhi)
                        )
                    )
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流干的禄是年支，流支刑冲穿原局或大运的印支或印干坐支',
                        'add' => 14
                    ];
                    $fumu += 14;
                }

            }
            $ret['fumu'][$num]['score'] = $fumu;

//            $temp[$j] = [
//                '桃花'=>$taohua,
//                '婚配'=>$taohua < 10 ? 0 : $hunpei,
//                '情变'=>$qingbian,
//                '转变'=>$zhuanbian,
//                '升职'=>$shengzhi,
//                '进财'=>$jincai,
//                '父母'=>$fumu,
//            ];

            $num++;
        }

        return json(['code' => 200, 'data' => $ret, 'msg' => 'Success.']);
    }

    /**
     * 桃花
     * @return mixed
     */
    public function get_taohua_to_json(Request $request)
    {
        $year = intval($request->input('year'));
        $end = intval($request->input('end'));// 计算的年数  如计算十年   $end=10;
        if (!$year) $year = intval(date("Y"));
        if ($end <= 0) $end = 0;

        $ret['bazi'] = implode($this->bazi);
        $ret['birth_sun_deg'] = $this->birth_sun_deg;
        $ret['sex'] = $this->sex;

        $st_year = date('Y', $this->st_time);
        $num = 0;
        for ($j = $year; $j <= $year + $end; $j++) {
            for ($i = $st_year; $i < $j; $i += 10) if ($j >= $i && $j < $i + 10) $st_year = $i;

            // 大运 干支
            $d_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($st_year)];
            $d_gan = mb_substr($d_gan_zhi, 0, 1, 'utf-8');// 大运天干
            $d_zhi = mb_substr($d_gan_zhi, 1, 1, 'utf-8');// 大运地支
            $dazhi = $this->canggan[$d_zhi][0];// 大运地支本气
            $y_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($j)];
            $y_gan = mb_substr($y_gan_zhi, 0, 1, 'utf-8');// 流年天干
            $y_zhi = mb_substr($y_gan_zhi, 1, 1, 'utf-8');// 流年地支
            $liuzhi = $this->canggan[$y_zhi][0];// 流年地支本气
            $rizhi = $this->canggan[$this->bazi[6]][0];// 本命地支本气

            $ret['taohua'][$num]['year'] = $j;
            $ret['taohua'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['taohua'][$num]['dayun_gan'] = $d_gan;
//            $ret['taohua'][$num]['dayun_zhi'] = $d_zhi;
            $ret['taohua'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['taohua'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['taohua'][$num]['liunian_gan'] = $y_gan;
//            $ret['taohua'][$num]['liunian_zhi'] = $y_zhi;
            $ret['taohua'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['taohua'][$num]['liunian_zhiqi'] = $liuzhi;

            $taohua = 0;
            // 1.干财官
            if (
                // 男命，流年天干为正财或偏财【+15】
                ($this->sex == 1 && ($this->shishen[$y_gan][$this->bazi[5]] == '正财'
                        || $this->shishen[$y_gan][$this->bazi[5]] == '偏财'))
                ||
                // 女命，流年天干为七杀或正官【+15】
                ($this->sex == 2 && ($this->shishen[$y_gan][$this->bazi[5]] == '七杀'
                        || $this->shishen[$y_gan][$this->bazi[5]] == '正官'))
            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '干财官:男命，流年天干为正财或偏财;女命，流年天干为七杀或正官.',
                    'add' => 15,
                ];
                $taohua += 15;
                // 此时地支为日干之禄【+15】
                if ($this->is_lushen($this->bazi[5], $y_zhi)) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '干财官:男命，流年天干为正财或偏财;女命，流年天干为七杀或正官. 此时地支为日干之禄',
                        'add' => 15,
                    ];
                    $taohua += 15;
                }
                // 此时地支为日支【+12】
                if ($this->bazi[6] == $y_zhi) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '干财官:男命，流年天干为正财或偏财;女命，流年天干为七杀或正官.此时地支为日支',
                        'add' => 15,
                    ];
                    $taohua += 12;
                }
            }
            // 2.支财官
            if (
                // 男命，流年地支为正财或偏财【+12】
                ($this->sex == 1 && ($this->shishen[$liuzhi][$this->bazi[5]] == '正财'
                        || $this->shishen[$liuzhi][$this->bazi[5]] == '偏财'))
                ||
                // 女命，流年地支为七杀或正官【+12】
                ($this->sex == 2 && ($this->shishen[$liuzhi][$this->bazi[5]] == '七杀'
                        || $this->shishen[$liuzhi][$this->bazi[5]] == '正官'))
            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '支财官:男命，流年地支为正财或偏财;女命，流年地支为七杀或正官.',
                    'add' => 12,
                ];
                $taohua += 12;
                // 此时天干为比肩【+13】
                if ($this->shishen[$y_gan][$this->bazi[5]] == '比肩') {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '支财官:男命，流年地支为正财或偏财;女命，流年地支为七杀或正官.此时天干为比肩',
                        'add' => 13,
                    ];
                    $taohua += 13;
                }
                // 此时天干与日干相合【+15】
                if ($this->is_liuhe($y_gan, $this->bazi[5])) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '支财官:男命，流年地支为正财或偏财;女命，流年地支为七杀或正官.此时天干与日干相合',
                        'add' => 15,
                    ];
                    $taohua += 15;
                }
            }
            // 3.天地合 流年地支与日支合【+8】
            if ($this->is_liuhe($y_zhi, $this->bazi[6])) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '天地合:流年地支与日支合.',
                    'add' => 8,
                ];
                $taohua += 8;
                // 此时天干也与日干合【+8】
                if ($this->is_liuhe($y_gan, $this->bazi[5])) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '天地合:流年地支与日支合.此时天干也与日干合',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
                // 此时日支为财（男）或官杀（女）【+8】
                if (
                    // 此时日支为财（男）【+8】
                    ($this->sex == 1 && ($this->shishen[$rizhi][$this->bazi[5]] == '正财'
                            || $this->shishen[$rizhi][$this->bazi[5]] == '偏财'))
                    ||
                    // 此时日支为官杀（女）【+8】
                    ($this->sex == 2 && ($this->shishen[$rizhi][$this->bazi[5]] == '七杀'
                            || $this->shishen[$rizhi][$this->bazi[5]] == '正官'))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '天地合:流年地支与日支合.此时日支为财（男）或官杀（女）',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            }
            // 4.冲日支
            if ($this->is_liuchong($y_zhi, $this->bazi[6])) {
                if (
                    // 此时流支为财（男）【+7】
                    ($this->sex == 1 && ($this->shishen[$liuzhi][$this->bazi[5]] == '正财'
                            || $this->shishen[$liuzhi][$this->bazi[5]] == '偏财'))
                    ||
                    // 此时流支为官杀（女）【+7】
                    ($this->sex == 2 && ($this->shishen[$liuzhi][$this->bazi[5]] == '七杀'
                            || $this->shishen[$liuzhi][$this->bazi[5]] == '正官'))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '冲日支:此时流支为财;此时流支为官杀.',
                        'add' => 7,
                    ];
                    $taohua += 7;
                }
                if (
                    // 此时日支为财（男）【+7】
                    ($this->sex == 1 && ($this->shishen[$rizhi][$this->bazi[5]] == '正财'
                            || $this->shishen[$rizhi][$this->bazi[5]] == '偏财'))
                    ||
                    // 此时日支为官杀（女）【+7】
                    ($this->sex == 2 && ($this->shishen[$rizhi][$this->bazi[5]] == '七杀'
                            || $this->shishen[$rizhi][$this->bazi[5]] == '正官'))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '冲日支:此时日支为财;此时日支为官杀.',
                        'add' => 7,
                    ];
                    $taohua += 7;
                }
                // 此时流干为比肩【+7】
                if ($this->shishen[$y_gan][$this->bazi[5]] == '比肩') {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '冲日支:此时流干为比肩.',
                        'add' => 7,
                    ];
                    $taohua += 7;
                }
                // 此时日支在命局或大运中被合【+7】
                if (
                    $this->is_liuhe($this->bazi[6], $this->bazi[2])
                    || $this->is_liuhe($this->bazi[6], $this->bazi[4])
                    || $this->is_liuhe($this->bazi[6], $this->bazi[8])
                    || $this->is_liuhe($this->bazi[6], $d_zhi)
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '冲日支:此时日支在命局或大运中被合.',
                        'add' => 7,
                    ];
                    $taohua += 7;
                }
                // 此时日支为辰戌丑未【+3】
                if (in_array($this->bazi[6], ['辰', '戌', '丑', '未'])) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '冲日支:此时日支为辰戌丑未.',
                        'add' => 3,
                    ];
                    $taohua += 3;
                }
            }
            // 5.桃花年：流年地支为日支所起的桃花【+5】
            if ($this->is_taohua($this->bazi[6], $y_zhi)) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '桃花年：流年地支为日支所起的桃花.',
                    'add' => 5,
                ];
                $taohua += 5;
            }
            // 流年地支为年支所起的桃花且流年地支在本命中或大运存在【+5】
            if (
                $this->is_taohua($this->bazi[2], $y_zhi)
                && (
                    $this->bazi[4] == $y_zhi
                    || $this->bazi[4] == $y_zhi
                    || $this->bazi[4] == $y_zhi
                    || $d_zhi == $y_zhi
                )
            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '流年地支为年支所起的桃花且流年地支在本命中或大运存在.',
                    'add' => 5,
                ];
                $taohua += 5;
            }
            // 6.合留 若原命局地支或大运地支本气财星（男）或本气官星（女）被冲或穿，流年地支来合【+8】
            $temp_arr = [$this->bazi[2], $this->bazi[4], $this->bazi[6], $this->bazi[8], $d_zhi];
            // 本命年支
            if (
                // 流年地支来合
                $this->is_liuhe($y_zhi, $this->bazi[2]) &&
                // 被冲或穿
                ($this->liuchong($this->bazi[2], $temp_arr) || $this->liuhai($this->bazi[2], $temp_arr))

            ) {
                if (
                    ($this->sex == 1 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[2]][0]][$this->bazi[5]], ['偏财', '正财']))
                    ||
                    ($this->sex == 2 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[2]][0]][$this->bazi[5]], ['七杀', '正官']))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '合留:若原命局年支本气财星（男）或本气官星（女）被冲或穿，流年地支来合.',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            } // 本命月支
            elseif (
                // 流年地支来合
                $this->is_liuhe($y_zhi, $this->bazi[4]) &&
                // 被冲或穿
                ($this->liuchong($this->bazi[4], $temp_arr) || $this->liuhai($this->bazi[4], $temp_arr))

            ) {
                if (
                    ($this->sex == 1 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[4]][0]][$this->bazi[5]], ['偏财', '正财']))
                    ||
                    ($this->sex == 2 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[4]][0]][$this->bazi[5]], ['七杀', '正官']))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '合留:若原命局月支本气财星（男）或本气官星（女）被冲或穿，流年地支来合.',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            } // 本命日支
            elseif (
                // 流年地支来合
                $this->is_liuhe($y_zhi, $this->bazi[6]) &&
                // 被冲或穿
                ($this->liuchong($this->bazi[6], $temp_arr) || $this->liuhai($this->bazi[6], $temp_arr))

            ) {
                if (
                    ($this->sex == 1 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[6]][0]][$this->bazi[5]], ['偏财', '正财']))
                    ||
                    ($this->sex == 2 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[6]][0]][$this->bazi[5]], ['七杀', '正官']))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '合留:若原命局日支本气财星（男）或本气官星（女）被冲或穿，流年地支来合.',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            } // 本命时支
            elseif (
                // 流年地支来合
                $this->is_liuhe($y_zhi, $this->bazi[8]) &&
                // 被冲或穿
                ($this->liuchong($this->bazi[8], $temp_arr) || $this->liuhai($this->bazi[8], $temp_arr))

            ) {
                if (
                    ($this->sex == 1 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[8]][0]][$this->bazi[5]], ['偏财', '正财']))
                    ||
                    ($this->sex == 2 &&
                        in_array($this->shishen[$this->canggan[$this->bazi[8]][0]][$this->bazi[5]], ['七杀', '正官']))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '合留:若原命局时支本气财星（男）或本气官星（女）被冲或穿，流年地支来合.',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            } // 大运地支
            elseif (
                // 流年地支来合
                $this->is_liuhe($y_zhi, $d_zhi) &&
                // 被冲或穿
                ($this->liuchong($d_zhi, $temp_arr) || $this->liuhai($d_zhi, $temp_arr))

            ) {
                if (
                    ($this->sex == 1 &&
                        in_array($this->shishen[$dazhi][$this->bazi[5]], ['偏财', '正财']))
                    ||
                    ($this->sex == 2 &&
                        in_array($this->shishen[$dazhi][$this->bazi[5]], ['七杀', '正官']))
                ) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '合留:若原命局大运地支本气财星（男）或本气官星（女）被冲或穿，流年地支来合.',
                        'add' => 8,
                    ];
                    $taohua += 8;
                }
            }
            // 7.运财官 大运地支本气为财（男）或官杀（女），流年地支合之【+10】，流年地支拱之【+7】，流年地支冲之【+5】，
            if (
                ($this->sex == 1 && in_array($this->shishen[$dazhi][$this->bazi[5]], ['偏财', '正财']))
                || ($this->sex == 2 && in_array($this->shishen[$dazhi][$this->bazi[5]], ['七杀', '正官']))
            ) {
                if ($this->is_liuhe($y_zhi, $d_zhi)) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '运财官 大运地支本气为财（男）或官杀（女），流年地支合之.',
                        'add' => 10,
                    ];
                    $taohua += 10;
                }
                if ($this->is_gong($y_zhi, $d_zhi)) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '运财官 大运地支本气为财（男）或官杀（女），流年地支拱之.',
                        'add' => 7,
                    ];
                    $taohua += 7;
                }
                if ($this->is_liuchong($y_zhi, $d_zhi)) {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '运财官 大运地支本气为财（男）或官杀（女），流年地支冲之.',
                        'add' => 5,
                    ];
                    $taohua += 5;
                }
            }
            // 8.禄出干 流年天干是财（男）或官杀（女），且其禄为本命地支或大运地支之一，【+8】
            if (
                (($this->sex == 1 && in_array($this->shishen[$y_gan][$this->bazi[5]], ['偏财', '正财']))
                    || ($this->sex == 2 && in_array($this->shishen[$y_gan][$this->bazi[5]], ['七杀', '正官'])))
                && (
                    $this->is_lushen($y_gan, $this->bazi[2])
                    || $this->is_lushen($y_gan, $this->bazi[4])
                    || $this->is_lushen($y_gan, $this->bazi[6])
                    || $this->is_lushen($y_gan, $this->bazi[8])
                    || $this->is_lushen($y_gan, $d_zhi)
                )
            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '禄出干:流年天干是财（男）或官杀（女），且其禄为本命地支或大运地支之一.',
                    'add' => 8,
                ];
                $taohua += 8;
            }
            // 9.宫出干 流年天干的禄是日支【+9】；
            if ($this->is_lushen($y_gan, $this->bazi[6])) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '宫出干:流年天干的禄是日支.',
                    'add' => 9,
                ];
                $taohua += 9;
            }
            // 日支是辰戌丑未，流干是日支非土藏干之一【+7】
            if (
                in_array($this->bazi[6], ['辰', '戌', '丑', '未'])
                && in_array($y_gan, [$this->canggan[$this->bazi[6]][1], $this->canggan[$this->bazi[6]][2]])
            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '日支是辰戌丑未，流干是日支非土藏干之一.',
                    'add' => 7,
                ];
                $taohua += 7;
                // 此时日干是壬癸【+3】
                if ($this->bazi[5] == '壬' || $this->bazi[5] == '癸') {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '日支是辰戌丑未，流干是日支非土藏干之一.此时日干是壬癸',
                        'add' => 3,
                    ];
                    $taohua += 3;
                }
            }
            // 10.支伏吟 若流年地支是四柱或大运地支有本气财（男）或官杀（女）【+6】
            if (in_array($y_zhi, $temp_arr) &&
                (($this->sex == 1 && in_array($this->shishen[$liuzhi][$this->bazi[5]], ['偏财', '正财']))
                    || ($this->sex == 2 && in_array($this->shishen[$liuzhi][$this->bazi[5]], ['七杀', '正官'])))

            ) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '支伏吟:若流年地支是四柱或大运地支有本气财（男）或官杀（女）',
                    'add' => 6,
                ];
                $taohua += 6;
            }
            // 11.宫伏吟 若流年地支是日支【+6】
            if ($this->bazi[6] == $y_zhi) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '宫伏吟:若流年地支是日支',
                    'add' => 6,
                ];
                $taohua += 6;
            }
            // 12.流年地支拱到日支【+6】
            if ($this->is_gong($this->bazi[6], $y_zhi)) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '流年地支拱到日支',
                    'add' => 6,
                ];
                $taohua += 6;
            }
            // 13.运比肩：流支合或冲运支，若此时运干比肩+3，运支合或拱日支+6，运支合或拱本命财星（男命，此财星是指某柱天干或地支本气）+6
            if ($this->is_liuhe($y_zhi, $d_zhi) || $this->is_liuchong($y_zhi, $d_zhi)) {
                if ($this->shishen[$d_gan][$this->bazi[5]] == '比肩') {
                    $ret['taohua'][$num]['condition'][] = [
                        'if' => '运比肩：流支合或冲运支，若此时运干比肩',
                        'add' => 3,
                    ];
                    $taohua += 3;
                    if ($this->is_liuhe($this->bazi[6], $d_zhi) || $this->is_gong($this->bazi[6], $d_zhi)) {
                        $ret['taohua'][$num]['condition'][] = [
                            'if' => '运比肩：流支合或冲运支，若此时运干比肩,运支合或拱日支',
                            'add' => 6,
                        ];
                        $taohua += 6;
                    }
                    if ($this->sex == 1) {
                        if (
                            (
                                ($this->is_liuhe($this->bazi[1], $d_zhi)
                                    || $this->is_gong($this->bazi[1], $d_zhi))
                                && in_array($this->shishen[$this->bazi[1]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[3], $d_zhi)
                                    || $this->is_gong($this->bazi[3], $d_zhi))
                                && in_array($this->shishen[$this->bazi[3]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[7], $d_zhi)
                                    || $this->is_gong($this->bazi[7], $d_zhi))
                                && in_array($this->shishen[$this->bazi[7]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[2], $d_zhi)
                                    || $this->is_gong($this->bazi[2], $d_zhi))
                                && in_array($this->shishen[$this->canggan[$this->bazi[2]][0]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[4], $d_zhi)
                                    || $this->is_gong($this->bazi[4], $d_zhi))
                                && in_array($this->shishen[$this->canggan[$this->bazi[4]][0]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[6], $d_zhi)
                                    || $this->is_gong($this->bazi[6], $d_zhi))
                                && in_array($this->shishen[$this->canggan[$this->bazi[6]][0]][$this->bazi[5]], ['偏财', '正财'])
                            )
                            ||
                            (
                                ($this->is_liuhe($this->bazi[8], $d_zhi)
                                    || $this->is_gong($this->bazi[8], $d_zhi))
                                && in_array($this->shishen[$this->canggan[$this->bazi[8]][0]][$this->bazi[5]], ['偏财', '正财'])
                            )
                        ) {
                            $ret['taohua'][$num]['condition'][] = [
                                'if' => '运比肩：流支合或冲运支，若此时运干比肩,运支合或拱日支,运支合或拱本命财星（男命，此财星是指某柱天干或地支本气）',
                                'add' => 6,
                            ];
                            $taohua += 6;
                        }
                    }
                }
            }
            $Third = new ThirdprogressedController();
            $Third->recode = $this->userinfo;
            $th_4_1 = json_decode($Third->get($j . "-4-1"), true)['data']['planets'];
            $th_10_1 = json_decode($Third->get($j . "-10-1"), true)['data']['planets'];
            $score_4_1 = 0;
            $score_10_1 = 0;
            if (isset($th_4_1[0]['phase']['0-3']) && $th_4_1[0]['phase']['0-3']['phase_e'] == 0) {
                $score_4_1 += 5;
                if (isset($th_4_1[3]['phase']['3-5'])) $score_4_1 += 5;
                if (in_array($th_4_1[3]['in_house_id'], [5, 7])) $score_4_1 += 5;
            }
            if (isset($th_4_1[3]['phase']['3-4']) && $th_4_1[3]['phase']['3-4']['phase_e'] == 0) {
                $score_4_1 += 5;
                if (isset($th_4_1[3]['phase']['3-5'])) $score_4_1 += 5;
                if (in_array($th_4_1[3]['in_house_id'], [5, 7])) $score_4_1 += 5;
            }
            if (isset($th_4_1[0]['phase']['0-4']) && $th_4_1[0]['phase']['0-4']['phase_e'] == 0) {
                $score_4_1 += 2;
                if (isset($th_4_1[4]['phase']['4-5'])) $score_4_1 += 5;
                if (in_array($th_4_1[3]['in_house_id'], [5, 7]) || in_array($th_4_1[4]['in_house_id'], [5, 7])) $score_4_1 += 5;
            }
            if ($score_4_1 == 0 && isset($th_4_1[3]['phase']['3-5'])) {
                $score_4_1 += 5;
                if (in_array($th_4_1[3]['in_house_id'], [5, 7]) || in_array($th_4_1[5]['in_house_id'], [5, 7])) $score_4_1 += 5;
            }
            if (isset($th_10_1[0]['phase']['0-3']) && $th_10_1[0]['phase']['0-3']['phase_e'] == 0) {
                $score_10_1 += 5;
                if (isset($th_10_1[3]['phase']['3-5'])) $score_10_1 += 5;
                if (in_array($th_10_1[3]['in_house_id'], [5, 7])) $score_10_1 += 5;
            }
            if (isset($th_10_1[3]['phase']['3-4']) && $th_10_1[3]['phase']['3-4']['phase_e'] == 0) {
                $score_10_1 += 5;
                if (isset($th_10_1[3]['phase']['3-5'])) $score_10_1 += 5;
                if (in_array($th_10_1[3]['in_house_id'], [5, 7])) $score_10_1 += 5;
            }
            if (isset($th_10_1[0]['phase']['0-4']) && $th_10_1[0]['phase']['0-4']['phase_e'] == 0) {
                $score_10_1 += 2;
                if (isset($th_10_1[4]['phase']['4-5'])) $score_10_1 += 5;
                if (in_array($th_10_1[3]['in_house_id'], [5, 7]) || in_array($th_10_1[4]['in_house_id'], [5, 7])) $score_10_1 += 5;
            }
            if ($score_10_1 == 0 && isset($th_10_1[3]['phase']['3-5'])) {
                $score_10_1 += 5;
                if (in_array($th_10_1[3]['in_house_id'], [5, 7]) || in_array($th_10_1[5]['in_house_id'], [5, 7])) $score_10_1 += 5;
            }
            if ($score_4_1 > $score_10_1) {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '三限4月1日',
                    'add' => $score_4_1,
                ];
                $taohua += $score_4_1;
            } else {
                $ret['taohua'][$num]['condition'][] = [
                    'if' => '三限10月1日',
                    'add' => $score_10_1,
                ];
                $taohua += $score_10_1;
            }
            $lv = 0;
            if ($taohua >= 30) $lv = 3;
            elseif ($taohua >= 20) $lv = 2;
            elseif ($taohua > 10) $lv = 1;
            $ret['taohua'][$num]['score'] = $taohua;
            $ret['taohua'][$num]['lv'] = $lv . '级';


            $ret['hunpei'][$num] = [];
            $ret['hunpei'][$num]['year'] = $j;
            $ret['hunpei'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['hunpei'][$num]['dayun_gan'] = $d_gan;
//            $ret['hunpei'][$num]['dayun_zhi'] = $d_zhi;
            $ret['hunpei'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['hunpei'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['hunpei'][$num]['liunian_gan'] = $y_gan;
//            $ret['hunpei'][$num]['liunian_zhi'] = $y_zhi;
            $ret['hunpei'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['hunpei'][$num]['liunian_zhiqi'] = $liuzhi;
//            if($taohua < 10) continue;// 前提：桃花10分以上（若不满足这个条件，婚配得分无效）
            ####################婚配######################
            $hunpei = 0;
            // 1、   印年：流干为印+10，流支本气为印+10；
            if ($this->is_ygs($y_gan, $this->bazi[5], '印')) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '印年：流干为印+10，',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            if ($this->is_ygs($liuzhi, $this->bazi[5], '印')) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '印年：流支本气为印+10；',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            // 2、   冲合印：流支冲或合本命或大运印支+10；
            if (
                (
                    $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '印')
                    &&
                    (
                        $this->is_liuchong($this->bazi[2], $y_zhi)
                        || $this->is_liuhe($this->bazi[2], $y_zhi)
                    )
                )
                ||
                (
                    $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '印')
                    &&
                    (
                        $this->is_liuchong($this->bazi[4], $y_zhi)
                        || $this->is_liuhe($this->bazi[4], $y_zhi)
                    )
                )
                ||
                (
                    $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '印')
                    &&
                    (
                        $this->is_liuchong($this->bazi[6], $y_zhi)
                        || $this->is_liuhe($this->bazi[6], $y_zhi)
                    )
                )
                ||
                (
                    $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '印')
                    &&
                    (
                        $this->is_liuchong($this->bazi[8], $y_zhi)
                        || $this->is_liuhe($this->bazi[8], $y_zhi)
                    )
                )
                ||
                (
                    $this->is_ygs($dazhi, $this->bazi[5], '印')
                    &&
                    (
                        $this->is_liuchong($d_zhi, $y_zhi)
                        || $this->is_liuhe($d_zhi, $y_zhi)
                    )
                )
            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '冲合印：流支冲或合本命或大运印支+10；',
                    'add' => 10
                ];
                $hunpei += 10;

            }
            // 流干合本命或大运印干+10
            if (
                (
                    $this->is_ygs($this->bazi[1], $this->bazi[5], '印')
                    && $this->is_wuhe($this->bazi[1], $y_gan)
                )
                ||
                (
                    $this->is_ygs($this->bazi[3], $this->bazi[5], '印')
                    && $this->is_wuhe($this->bazi[3], $y_gan)
                )
                ||
                (
                    $this->is_ygs($this->bazi[7], $this->bazi[5], '印')
                    && $this->is_wuhe($this->bazi[7], $y_gan)
                )
                ||
                (
                    $this->is_ygs($d_gan, $this->bazi[5], '印')
                    && $this->is_wuhe($d_gan, $y_gan)
                )
            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '流干合本命或大运印干+10',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            // 3、   破比劫：
            //  男命原局“争财”，流年干为食伤，地支为本气财星+13，若此时流支与日支合拱，则+7；
            //  女命原局“争官”，流年干为财星，地支为本气官杀+13，若此时流支与日支合拱，则+7
            if ($this->is_zc_zg($this->sex, $this->bazi)) {
                if (
                    $this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[5], '食伤')
                    && $this->is_ygs($liuzhi, $this->bazi[5], '财')
                ) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '男命原局“争财”，流年干为食伤，地支为本气财星',
                        'add' => 13
                    ];
                    $hunpei += 13;

                    if ($this->is_liuhe($y_zhi, $this->bazi[6])
                        || $this->is_gong($y_zhi, $this->bazi[6])) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '男命原局“争财”，流年干为食伤，地支为本气财星，若此时流支与日支合拱',
                            'add' => 7
                        ];
                        $hunpei += 7;
                    }
                } elseif ($this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[5], '财')
                    && $this->is_ygs($liuzhi, $this->bazi[5], '官杀')) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '女命原局“争官”，流年干为财星，地支为本气官杀',
                        'add' => 7
                    ];
                    $hunpei += 13;

                    if ($this->is_liuhe($y_zhi, $this->bazi[6])
                        || $this->is_gong($y_zhi, $this->bazi[6])) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '女命原局“争官”，流年干为财星，地支为本气官杀,若此时流支与日支合拱',
                            'add' => 7
                        ];
                        $hunpei += 7;
                    }
                }
            }
            // 4、   破伤官：女命日坐伤官，流支为本气印星与日支冲合拱+10；女命天干伤官，流干为财或印+10
            if ($this->sex == 2) {
                if (
                    $this->is_ygs($rizhi, $this->bazi[5], '伤官')
                    && $this->is_ygs($liuzhi, $this->bazi[5], '印')
                    && (
                        $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuhe($y_zhi, $this->bazi[6])
                        || $this->is_gong($y_zhi, $this->bazi[6])
                    )
                ) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破伤官：女命日坐伤官，流支为本气印星与日支冲合拱',
                        'add' => 10
                    ];
                    $hunpei += 10;
                }
                if (
                    (
                        $this->is_ygs($this->bazi[1], $this->bazi[5], '伤官')
                        || $this->is_ygs($this->bazi[3], $this->bazi[5], '伤官')
                        || $this->is_ygs($this->bazi[7], $this->bazi[5], '伤官')
                    )
                    &&
                    (
                        $this->is_ygs($y_gan, $this->bazi[5], '财')
                        || $this->is_ygs($y_gan, $this->bazi[5], '印')
                    )
                ) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破伤官：女命天干伤官，流干为财或印',
                        'add' => 10
                    ];
                    $hunpei += 10;
                }
            }
            // 5、   破穿：若原局日支与它支相害，流支与日支相冲或相合+10
            if (
                (
                    $this->is_liuhai($this->bazi[2], $this->bazi[6])
                    || $this->is_liuhai($this->bazi[4], $this->bazi[6])
                    || $this->is_liuhai($this->bazi[8], $this->bazi[6])
                )
                &&
                (
                    $this->is_liuchong($y_zhi, $this->bazi[6])
                    || $this->is_liuhe($y_zhi, $this->bazi[6])
                )
            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '破穿：若原局日支与它支相害，流支与日支相冲或相合',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            // 6、   破冲：若原局日支与它支相冲，流支与日支相合+10，与日支相害+7，与日支相拱+5
            if (
            (
                $this->is_liuchong($this->bazi[2], $this->bazi[6])
                || $this->is_liuchong($this->bazi[4], $this->bazi[6])
                || $this->is_liuchong($this->bazi[8], $this->bazi[6])
            )
            ) {
                if ($this->is_liuhe($y_zhi, $this->bazi[6])) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破冲：若原局日支与它支相冲，流支与日支相合',
                        'add' => 10
                    ];
                    $hunpei += 10;
                }
                if ($this->is_liuhai($y_zhi, $this->bazi[6])) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破冲：若原局日支与它支相冲，流支与日支相害',
                        'add' => 7
                    ];
                    $hunpei += 7;
                }
                if ($this->is_gong($y_zhi, $this->bazi[6])) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破冲：若原局日支与它支相冲，流支与日支相拱',
                        'add' => 5
                    ];
                    $hunpei += 5;
                }

            }
            // 7、   破合：若原局日支与它支相合，流支与日支相冲+10
            if (
                (
                    $this->is_liuhe($this->bazi[2], $this->bazi[6])
                    || $this->is_liuhe($this->bazi[4], $this->bazi[6])
                    || $this->is_liuhe($this->bazi[8], $this->bazi[6])
                )
                && $this->is_liuchong($y_zhi, $this->bazi[6])
            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '破合：若原局日支与它支相合，流支与日支相冲',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            // 8、   破墓：若本命日支为辰戌丑未，且不见刑冲，流支刑冲日支+7，若此时天干是财（男命）官杀（女命），+8
            if (in_array($this->bazi[6], ['辰', '戌', '丑', '未'])) {
                if (
                    !$this->is_xing($this->bazi[2], $this->bazi[6])
                    && !$this->is_xing($this->bazi[4], $this->bazi[6])
                    && !$this->is_xing($this->bazi[8], $this->bazi[6])
                    && !$this->is_liuchong($this->bazi[2], $this->bazi[6])
                    && !$this->is_liuchong($this->bazi[4], $this->bazi[6])
                    && !$this->is_liuchong($this->bazi[8], $this->bazi[6])
                    &&
                    (
                        $this->is_xing($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                    )
                ) {
                    $ret['hunpei'][$num]['condition'][] = [
                        'if' => '破墓：若本命日支为辰戌丑未，且不见刑冲，流支刑冲日支',
                        'add' => 7
                    ];
                    $hunpei += 7;

                    if (
                        (
                            $this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[5], '财')
                        )
                        ||
                        (
                            $this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[5], '官杀')
                        )
                    ) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '破墓：若本命日支为辰戌丑未，且不见刑冲，流支刑冲日支,若此时天干是财（男命）官杀（女命）',
                            'add' => 8
                        ];
                        $hunpei += 8;
                    }
                }
            }
            // 9、   财官入宫：
            // 男命流干财星，流支为日支+15，流支与日支合+14，流支与日支拱+10，流支与原局财星相合或相拱+10；
            // 女命流干官杀，流支为日支+15，流支与日支合+14，流支与日支拱+10，流支与原局官杀相合或相拱+10
            // 【日支可用本命比肩坐支代替，如果本命天干有比肩的话】
            // 日支 + 本命比肩坐支
            $rz = [$this->bazi[6]];
            if ($this->shishen[$this->bazi[1]][$this->bazi[5]] == '比肩'
                && $this->bazi[2] != $this->bazi[6])
                $rz[] = $this->bazi[2];
            if ($this->shishen[$this->bazi[3]][$this->bazi[5]] == '比肩'
                && $this->bazi[4] != $this->bazi[6])
                $rz[] = $this->bazi[4];
            if ($this->shishen[$this->bazi[7]][$this->bazi[5]] == '比肩'
                && $this->bazi[8] != $this->bazi[6])
                $rz[] = $this->bazi[8];
            if ($this->sex == 1 || $this->sex == 2) {
                if (
                    ($this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[5], '财'))
                    || ($this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[5], '官杀'))
                ) {
                    foreach ($rz as $z) {
                        if ($y_zhi == $z) {
                            $ret['hunpei'][$num]['condition'][] = [
                                'if' => '财官入宫：男命流干财星/女命流干官杀，流支为日支',
                                'add' => 15
                            ];
                            $hunpei += 15;
                        } elseif ($this->is_liuhe($y_zhi, $z)) {
                            $ret['hunpei'][$num]['condition'][] = [
                                'if' => '财官入宫：男命流干财星/女命流干官杀，流支合日支',
                                'add' => 14
                            ];
                            $hunpei += 14;
                        } elseif ($this->is_gong($y_zhi, $z)) {
                            $ret['hunpei'][$num]['condition'][] = [
                                'if' => '财官入宫：男命流干财星/女命流干官杀，流支拱日支',
                                'add' => 10
                            ];
                            $hunpei += 10;
                        }
                    }
                    if (
                        (
                            (
                                $this->sex == 1
                                && $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '财')
                            )
                            ||
                            (
                                $this->sex == 2
                                && $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '官杀')
                            )
                        )
                        &&
                        (
                            $this->is_liuhe($y_zhi, $this->bazi[2])
                            || $this->is_gong($y_zhi, $this->bazi[2])
                        )
                    ) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '财官入宫：男命流干财星/女命流干官杀，流支与原局【2】财星相合或相拱',
                            'add' => 10
                        ];
                        $hunpei += 10;
                    }
                    if (
                        (
                            (
                                $this->sex == 1
                                && $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '财')
                            )
                            ||
                            (
                                $this->sex == 2
                                && $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '官杀')
                            )
                        )
                        &&
                        (
                            $this->is_liuhe($y_zhi, $this->bazi[4])
                            || $this->is_gong($y_zhi, $this->bazi[4])
                        )
                    ) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '财官入宫：男命流干财星/女命流干官杀，流支与原局【4】财星相合或相拱',
                            'add' => 10
                        ];
                        $hunpei += 10;
                    }
                    if (
                        (
                            (
                                $this->sex == 1
                                && $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '财')
                            )
                            ||
                            (
                                $this->sex == 2
                                && $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '官杀')
                            )
                        )
                        &&
                        (
                            $this->is_liuhe($y_zhi, $this->bazi[6])
                            || $this->is_gong($y_zhi, $this->bazi[6])
                        )
                    ) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '财官入宫：男命流干财星/女命流干官杀，流支与原局【6】财星相合或相拱',
                            'add' => 10
                        ];
                        $hunpei += 10;
                    }
                    if (
                        (
                            (
                                $this->sex == 1
                                && $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '财')
                            )
                            ||
                            (
                                $this->sex == 2
                                && $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '官杀')
                            )
                        )
                        &&
                        (
                            $this->is_liuhe($y_zhi, $this->bazi[8])
                            || $this->is_gong($y_zhi, $this->bazi[8])
                        )
                    ) {
                        $ret['hunpei'][$num]['condition'][] = [
                            'if' => '财官入宫：男命流干财星/女命流干官杀，流支与原局【8】财星相合或相拱',
                            'add' => 10
                        ];
                        $hunpei += 10;
                    }
                }
            }
            // 10、  财官入宫二：
            // 男命运干或本命天干有财星，流干来合该财星，流支=日支（或本命比肩坐支）；
            // 女命运干或本命天干有官杀，流干来合该官星，流支=日支（或本命比肩坐支）
            $liuzhi_rizhi = false;
            foreach ($rz as $z) {
                if ($y_zhi == $z) $liuzhi_rizhi = true;
                continue;
            }
            if (
                (
                    (
                        (
                            $this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[1], '财')
                            ||
                            $this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[1], '官杀')
                        )
                        && $this->is_wuhe($y_gan, $this->bazi[1])
                    )
                    ||
                    (
                        (
                            $this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[3], '财')
                            ||
                            $this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[3], '官杀')
                        )
                        && $this->is_wuhe($y_gan, $this->bazi[3])
                    )
                    ||
                    (
                        (
                            $this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[7], '财')
                            ||
                            $this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[7], '官杀')
                        )
                        && $this->is_wuhe($y_gan, $this->bazi[7])
                    )
                    ||
                    (
                        (
                            $this->sex == 1 && $this->is_ygs($y_gan, $d_gan, '财')
                            ||
                            $this->sex == 2 && $this->is_ygs($y_gan, $d_gan, '官杀')
                        )
                        && $this->is_wuhe($y_gan, $d_gan)
                    )
                )
                && $liuzhi_rizhi === true

            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '10、    财官入宫二：男命运干或本命天干有财星，流干来合该财星，流支=日支（或本命比肩坐支）；女命运干或本命天干有官杀，流干来合该官星，流支=日支（或本命比肩坐支）',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            // 11、  财官入宫三：
            //  男命运干为财星，流支是日支或合拱日支+10；
            //  女命运干为官杀，流支是日支或合拱日支+10
            if (
                (
                    $this->sex == 1 && $this->is_ygs($y_gan, $d_gan, '财')
                    ||
                    $this->sex == 2 && $this->is_ygs($y_gan, $d_gan, '官杀')
                )
                &&
                (
                    $liuzhi_rizhi === true
                    || $this->is_liuhe($y_zhi, $this->bazi[6])
                    || $this->is_gong($y_zhi, $this->bazi[6])
                )
            ) {
                $ret['hunpei'][$num]['condition'][] = [
                    'if' => '财官入宫三：男命运干为财星，流支是日支或合拱日支；女命运干为官杀，流支是日支或合拱日支',
                    'add' => 10
                ];
                $hunpei += 10;
            }
            $ret['hunpei'][$num]['taohua_score'] = $taohua;
            $ret['hunpei'][$num]['score'] = $hunpei;

            $num++;
        }
        return json(['code' => 200, 'data' => $ret, 'msg' => 'Success.']);
    }

    /**
     * 婚配
     * @return mixed
     */
    public function get_hunpei()
    {

    }

    /**
     * 情变
     * @return mixed
     */
    public function get_qingbian_to_json(Request $request)
    {
        $year = intval($request->input('year'));
        $end = intval($request->input('end'));// 计算的年数  如计算十年   $end=10;
        if (!$year) $year = intval(date("Y"));
        if ($end <= 0) $end = 0;

        $ret['bazi'] = implode($this->bazi);
        $ret['birth_sun_deg'] = $this->birth_sun_deg;
        $ret['sex'] = $this->sex;

        $st_year = date('Y', $this->st_time);
        $num = 0;
        for ($j = $year; $j <= $year + $end; $j++) {
            for ($i = $st_year; $i < $j; $i += 10) if ($j >= $i && $j < $i + 10) $st_year = $i;

            // 大运 干支
            $d_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($st_year)];
            $d_gan = mb_substr($d_gan_zhi, 0, 1, 'utf-8');// 大运天干
            $d_zhi = mb_substr($d_gan_zhi, 1, 1, 'utf-8');// 大运地支
            $dazhi = $this->canggan[$d_zhi][0];// 大运地支本气
            $y_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($j)];
            $y_gan = mb_substr($y_gan_zhi, 0, 1, 'utf-8');// 流年天干
            $y_zhi = mb_substr($y_gan_zhi, 1, 1, 'utf-8');// 流年地支
            $liuzhi = $this->canggan[$y_zhi][0];// 流年地支本气
            $rizhi = $this->canggan[$this->bazi[6]][0];// 本命地支本气

            $ret['qingbian'][$num]['year'] = $j;
            $ret['qingbian'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['qingbian'][$num]['dayun_gan'] = $d_gan;
//            $ret['qingbian'][$num]['dayun_zhi'] = $d_zhi;
            $ret['qingbian'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['qingbian'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['qingbian'][$num]['liunian_gan'] = $y_gan;
//            $ret['qingbian'][$num]['liunian_zhi'] = $y_zhi;
            $ret['qingbian'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['qingbian'][$num]['liunian_zhiqi'] = $liuzhi;

            $qingbian = 0;
            // 1、合穿：流年与本命日柱支穿+5，
            //  若此时流干合日干+8，女命流干正官或男命流干正财+5，
            //  女命流支本气官杀或男命流支本气财星+5，女命流干官杀或男命流干财星+5，
            //  原局或运支有流支+5
            if ($this->is_liuhai($y_zhi, $this->bazi[6])) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '合穿：流年与本命日柱支穿',
                    'add' => 5
                ];
                $qingbian += 5;
                if ($this->is_wuhe($y_gan, $this->bazi[5])) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支穿,若此时流干合日干',
                        'add' => 8
                    ];
                    $qingbian += 8;
                }
                if (
                    ($this->sex == 1 && $this->shishen[$y_gan][$this->bazi[5]] == '正财')
                    || ($this->sex == 2 && $this->shishen[$y_gan][$this->bazi[5]] == '正官')
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支穿,女命流干正官或男命流干正财',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    ($this->sex == 1 && $this->is_ygs($liuzhi, $this->bazi[5], '财'))
                    || ($this->sex == 2 && $this->is_ygs($liuzhi, $this->bazi[5], '官杀'))
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支穿,女命流支本气官杀或男命流支本气财星',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    ($this->sex == 1 && $this->is_ygs($y_gan, $this->bazi[5], '财'))
                    || ($this->sex == 2 && $this->is_ygs($y_gan, $this->bazi[5], '官杀'))
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支穿,女命流干官杀或男命流干财星',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    $this->bazi[2] == $y_zhi
                    || $this->bazi[4] == $y_zhi
                    || $this->bazi[6] == $y_zhi
                    || $this->bazi[7] == $y_zhi
                    || $d_zhi == $y_zhi
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支穿,原局或运支有流支',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
            }
            // 2、合刑：流年与本命日柱支刑+5，
            //  若此时流干合日干+8，女命流干正官或男命流干正财+5，
            //  女命流支本气官杀或男命流支本气财星+5，
            //  原局或运支有流支+5，原局或运支有日支的冲支+5。
            if ($this->is_xing($y_zhi, $this->bazi[6])) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '合穿：流年与本命日柱支刑',
                    'add' => 5
                ];
                $qingbian += 5;
                if ($this->is_wuhe($y_gan, $this->bazi[5])) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支刑,若此时流干合日干',
                        'add' => 8
                    ];
                    $qingbian += 8;
                }
                if (
                    ($this->sex == 1 && $this->shishen[$y_gan][$this->bazi[5]] == '正财')
                    || ($this->sex == 2 && $this->shishen[$y_gan][$this->bazi[5]] == '正官')
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支刑,女命流干正官或男命流干正财',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    ($this->sex == 1 && $this->is_ygs($liuzhi, $this->bazi[5], '财'))
                    || ($this->sex == 2 && $this->is_ygs($liuzhi, $this->bazi[5], '官杀'))
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支刑,女命流支本气官杀或男命流支本气财星',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    $this->bazi[2] == $y_zhi
                    || $this->bazi[4] == $y_zhi
                    || $this->bazi[6] == $y_zhi
                    || $this->bazi[7] == $y_zhi
                    || $d_zhi == $y_zhi
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支刑,原局或运支有流支',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
                if (
                    $this->is_liuchong($this->bazi[2], $this->bazi[6])
                    || $this->is_liuchong($this->bazi[4], $this->bazi[6])
                    || $this->is_liuchong($this->bazi[8], $this->bazi[6])
                    || $this->is_liuchong($d_zhi, $this->bazi[6])
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '合穿：流年与本命日柱支刑,原局或运支有日支的冲支',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
            }
            // 3、穿财（男）：流支与本命大运财支相害||流支害本命大运财星坐支||流干为财且流支害本命大运日支外的某支+6，若此时流干与穿柱之干或日干相合，+5，
            if ($this->sex == 1) {
                $cg = '财';
            } // 4、穿官杀（女）：流支与本命大运官杀支相害||流支害本命大运官杀坐支||流干为官杀且流支害本命大运日支外的某支+6，若此时流干与穿柱之干或日干相合，+5，
            elseif ($this->sex == 2) {
                $cg = '官杀';
            }
            if (
                (
                    ($this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[2]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[4]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[6]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[8]))
                    ||
                    ($this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $d_zhi))
                )
                ||
                (
                    ($this->is_ygs($this->bazi[1], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[2]))
                    ||
                    ($this->is_ygs($this->bazi[3], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[4]))
                    ||
                    ($this->is_ygs($this->bazi[7], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[8]))
                    ||
                    ($this->is_ygs($d_gan, $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $d_zhi))
                )
                ||
                (
                    $this->is_ygs($d_gan, $this->bazi[5], $cg)
                    &&
                    (
                        ($this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                            && $this->is_liuhai($y_zhi, $this->bazi[2]))
                        ||
                        ($this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                            && $this->is_liuhai($y_zhi, $this->bazi[4]))
                        ||
                        ($this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                            && $this->is_liuhai($y_zhi, $this->bazi[8]))
                        ||
                        ($this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                            && $this->is_liuhai($y_zhi, $d_zhi))
                    )
                )
            ) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '流支与本命大运财支相害||流支害本命大运财星坐支||流干为财且流支害本命大运日支外的某支',
                    'add' => 6
                ];
                $qingbian += 6;
                if (
                    $this->is_wuhe($y_gan, $this->bazi[5])
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[2])
                        && $this->is_wuhe($y_gan, $this->bazi[1])
                    )
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[4])
                        && $this->is_wuhe($y_gan, $this->bazi[3])
                    )
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $this->bazi[8])
                        && $this->is_wuhe($y_gan, $this->bazi[7])
                    )
                    || (
                        $this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                        && $this->is_liuhai($y_zhi, $d_zhi)
                        && $this->is_wuhe($y_gan, $d_gan)
                    )
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '流支与本命大运财支相害||流支害本命大运财星坐支||流干为财且流支害本命大运日支外的某支,若此时流干与穿柱之干或日干相合',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
            }
            // 5、刑财官：【参考3/4两条，将穿害替换为刑】
            if (
                (
                    ($this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[2]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[4]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[6]))
                    ||
                    ($this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[8]))
                    ||
                    ($this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $d_zhi))
                )
                ||
                (
                    ($this->is_ygs($this->bazi[1], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[2]))
                    ||
                    ($this->is_ygs($this->bazi[3], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[4]))
                    ||
                    ($this->is_ygs($this->bazi[7], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[8]))
                    ||
                    ($this->is_ygs($d_gan, $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $d_zhi))
                )
                ||
                (
                    $this->is_ygs($d_gan, $this->bazi[5], $cg)
                    &&
                    (
                        ($this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                            && $this->is_xing($y_zhi, $this->bazi[2]))
                        ||
                        ($this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                            && $this->is_xing($y_zhi, $this->bazi[4]))
                        ||
                        ($this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                            && $this->is_xing($y_zhi, $this->bazi[8]))
                        ||
                        ($this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                            && $this->is_xing($y_zhi, $d_zhi))
                    )
                )
            ) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '流支与本命大运财支相刑||流支害本命大运财星坐支||流干为财且流支害本命大运日支外的某支',
                    'add' => 6
                ];
                $qingbian += 6;
                if (
                    $this->is_wuhe($y_gan, $this->bazi[5])
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[2])
                        && $this->is_wuhe($y_gan, $this->bazi[1])
                    )
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[4])
                        && $this->is_wuhe($y_gan, $this->bazi[3])
                    )
                    || (
                        $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $this->bazi[8])
                        && $this->is_wuhe($y_gan, $this->bazi[7])
                    )
                    || (
                        $this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], $cg)
                        && $this->is_xing($y_zhi, $d_zhi)
                        && $this->is_wuhe($y_gan, $d_gan)
                    )
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '流支与本命大运财支相刑||流支害本命大运财星坐支||流干为财且流支害本命大运日支外的某支,若此时流干与穿柱之干或日干相合',
                        'add' => 5
                    ];
                    $qingbian += 5;
                }
            }
            // 6、劫伤：
            //  男命流干为劫财+5，此时流支本气比肩劫财+4；
            //  女命流干为伤官+5，此时流支本气为食神伤官+4
            if ($this->sex == 1 && $this->shishen[$y_gan][$this->bazi[5]] == '劫财') {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '男命流干为劫财',
                    'add' => 5
                ];
                $qingbian += 5;
                if ($this->is_ygs($liuzhi, $this->bazi[5], '比劫')) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '男命流干为劫财，此时流支本气比肩劫财',
                        'add' => 4
                    ];
                    $qingbian += 4;
                }
            } elseif ($this->sex == 2 && $this->shishen[$y_gan][$this->bazi[5]] == '伤官') {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '女命流干为伤官',
                    'add' => 5
                ];
                $qingbian += 5;
                if ($this->is_ygs($liuzhi, $this->bazi[5], '食伤')) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '女命流干为伤官，此时流支本气为食神伤官',
                        'add' => 5
                    ];
                    $qingbian += 4;
                }
            }
            // 7、反吟：流干比肩，日支与流支冲，+7，若此时流支与运支冲，+6
            if ($this->shishen[$y_gan][$this->bazi[5]] == '比肩'
                && $this->is_liuchong($this->bazi[6], $y_zhi)) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '流干比肩，日支与流支冲',
                    'add' => 7
                ];
                $qingbian += 7;
                if ($this->is_liuchong($d_zhi, $y_zhi)) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '流干比肩，日支与流支冲，若此时流支与运支冲',
                        'add' => 6
                    ];
                    $qingbian += 6;
                }
            }
            // 8、伏吟1：日支在本命中受刑穿，或日支在本命中受冲且日支为夫妻星（男命财星女命官杀），此时流干比肩且流支为日支+12
            if (
                (
                    $this->is_xing($this->bazi[6], $this->bazi[2])
                    || $this->is_liuhai($this->bazi[6], $this->bazi[2])
                    || $this->is_xing($this->bazi[6], $this->bazi[4])
                    || $this->is_liuhai($this->bazi[6], $this->bazi[4])
                    || $this->is_xing($this->bazi[6], $this->bazi[8])
                    || $this->is_liuhai($this->bazi[6], $this->bazi[8])
                )
                ||
                (
                    $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], $cg)
                    &&
                    (
                        $this->is_liuchong($this->bazi[6], $this->bazi[2])
                        || $this->is_liuchong($this->bazi[6], $this->bazi[4])
                        || $this->is_liuchong($this->bazi[6], $this->bazi[8])
                    )
                )
            ) {
                if (
                    $this->shishen[$y_gan][$this->bazi[5]] == '比肩'
                    && $y_zhi == $this->bazi[6]
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '日支在本命中受刑穿，或日支在本命中受冲且日支为夫妻星（男命财星女命官杀），此时流干比肩且流支为日支',
                        'add' => 12
                    ];
                    $qingbian += 12;
                }
            }
            // 9、伏吟2：日支受大运刑穿，或日支受运支冲且日支为夫妻星（男命财星女命官杀），此时流干比肩且流支为日支+12
            if (
                (
                    $this->is_xing($this->bazi[6], $d_zhi)
                    || $this->is_liuhai($this->bazi[6], $d_zhi)
                )
                ||
                (
                    $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], $cg)
                    && $this->is_liuchong($this->bazi[6], $d_zhi)
                )
            ) {
                if (
                    $this->shishen[$y_gan][$this->bazi[5]] == '比肩'
                    && $y_zhi == $this->bazi[6]
                ) {
                    $ret['qingbian'][$num]['condition'][] = [
                        'if' => '日支受大运刑穿，或日支受运支冲且日支为夫妻星（男命财星女命官杀），此时流干比肩且流支为日支',
                        'add' => 12
                    ];
                    $qingbian += 12;
                }
            }
            // 10、夺财官：本命天干有官杀（女）或财（男）被 本命或大运 日干外的天干所合，流年遇到该天干+10
            if (
                (
                    $this->is_ygs($this->bazi[1], $this->bazi[5], $cg)
                    &&
                    (
                        (
                            $this->is_wuhe($this->bazi[1], $this->bazi[3])
                            && $y_gan == $this->bazi[3]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[1], $this->bazi[7])
                            && $y_gan == $this->bazi[7]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[1], $d_gan)
                            && $y_gan == $d_gan
                        )
                    )
                )
                ||
                (
                    $this->is_ygs($this->bazi[3], $this->bazi[5], $cg)
                    &&
                    (
                        (
                            $this->is_wuhe($this->bazi[3], $this->bazi[1])
                            && $y_gan == $this->bazi[1]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[3], $this->bazi[7])
                            && $y_gan == $this->bazi[7]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[3], $d_gan)
                            && $y_gan == $d_gan
                        )
                    )
                )
                ||
                (
                    $this->is_ygs($this->bazi[7], $this->bazi[5], $cg)
                    &&
                    (
                        (
                            $this->is_wuhe($this->bazi[7], $this->bazi[1])
                            && $y_gan == $this->bazi[1]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[7], $this->bazi[3])
                            && $y_gan == $this->bazi[3]
                        )
                        ||
                        (
                            $this->is_wuhe($this->bazi[3], $d_gan)
                            && $y_gan == $d_gan
                        )
                    )
                )
            ) {
                $ret['qingbian'][$num]['condition'][] = [
                    'if' => '本命天干有官杀（女）或财（男）被 本命或大运 日干外的天干所合，流年遇到该天干',
                    'add' => 10
                ];
                $qingbian += 10;
            }
            $ret['qingbian'][$num]['score'] = $qingbian;
            $num++;
        }
//        echo "<pre>";
//        print_r($ret);
        return json(['code' => 200, 'data' => $ret, 'msg' => 'Success.']);
    }

    /**
     * 转变
     * @return mixed
     */
    public function get_zhuanbian_to_json(Request $request)
    {
        $year = intval($request->input('year'));
        $end = intval($request->input('end'));// 计算的年数  如计算十年   $end=10;
        if (!$year) $year = intval(date("Y"));
        if ($end <= 0) $end = 0;

        $ret['bazi'] = implode($this->bazi);
        $ret['birth_sun_deg'] = $this->birth_sun_deg;
        $ret['sex'] = $this->sex;

        $st_year = date('Y', $this->st_time);
        $num = 0;
        for ($j = $year; $j <= $year + $end; $j++) {
            for ($i = $st_year; $i < $j; $i += 10) if ($j >= $i && $j < $i + 10) $st_year = $i;

            // 大运 干支
            $d_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($st_year)];
            $d_gan = mb_substr($d_gan_zhi, 0, 1, 'utf-8');// 大运天干
            $d_zhi = mb_substr($d_gan_zhi, 1, 1, 'utf-8');// 大运地支
            $dazhi = $this->canggan[$d_zhi][0];// 大运地支本气
            $y_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($j)];
            $y_gan = mb_substr($y_gan_zhi, 0, 1, 'utf-8');// 流年天干
            $y_zhi = mb_substr($y_gan_zhi, 1, 1, 'utf-8');// 流年地支
            $liuzhi = $this->canggan[$y_zhi][0];// 流年地支本气
            $rizhi = $this->canggan[$this->bazi[6]][0];// 本命地支本气

            $ret['zhuanbian'][$num]['year'] = $j;
            $ret['zhuanbian'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['zhuanbian'][$num]['dayun_gan'] = $d_gan;
//            $ret['zhuanbian'][$num]['dayun_zhi'] = $d_zhi;
            $ret['zhuanbian'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['zhuanbian'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['zhuanbian'][$num]['liunian_gan'] = $y_gan;
//            $ret['zhuanbian'][$num]['liunian_zhi'] = $y_zhi;
            $ret['zhuanbian'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['zhuanbian'][$num]['liunian_zhiqi'] = $liuzhi;

            $zhuanbian = 0;

            // 1、正冲：流干比肩，且流支与本命或大运某支相冲，+10；
            if (
                $this->shishen[$y_gan][$this->bazi[5]] == '比肩'
                &&
                (
                    $this->is_liuchong($y_zhi, $this->bazi[2])
                    || $this->is_liuchong($y_zhi, $this->bazi[4])
                    || $this->is_liuchong($y_zhi, $this->bazi[6])
                    || $this->is_liuchong($y_zhi, $this->bazi[8])
                    || $this->is_liuchong($y_zhi, $d_zhi)
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '正冲：流干比肩，且流支与本命或大运某支相冲',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 2、冲日：流支与日支相冲+10
            if ($this->is_liuchong($y_zhi, $this->bazi[6])) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '冲日：流支与日支相冲',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 3、冲禄：本命或大运有日干之禄，流支冲该禄，+10；
            if (
                (
                    $this->is_lushen($this->bazi[5], $this->bazi[2])
                    && $this->is_liuchong($y_zhi, $this->bazi[2])
                )
                ||
                (
                    $this->is_lushen($this->bazi[5], $this->bazi[4])
                    && $this->is_liuchong($y_zhi, $this->bazi[4])
                )
                ||
                (
                    $this->is_lushen($this->bazi[5], $this->bazi[6])
                    && $this->is_liuchong($y_zhi, $this->bazi[6])
                )
                ||
                (
                    $this->is_lushen($this->bazi[5], $this->bazi[8])
                    && $this->is_liuchong($y_zhi, $this->bazi[8])
                )
                ||
                (
                    $this->is_lushen($this->bazi[5], $d_zhi)
                    && $this->is_liuchong($y_zhi, $d_zhi)
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '冲禄：本命或大运有日干之禄，流支冲该禄',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 4、冲比肩坐支：若本命或大运有比肩，流支冲比肩坐支，+5
            if (
                (
                    $this->shishen[$this->bazi[1]][$this->bazi[5]] == '比肩'
                    && $this->is_liuchong($y_zhi, $this->bazi[2])
                )
                ||
                (
                    $this->shishen[$this->bazi[3]][$this->bazi[5]] == '比肩'
                    && $this->is_liuchong($y_zhi, $this->bazi[4])
                )
                ||
                (
                    $this->shishen[$this->bazi[7]][$this->bazi[5]] == '比肩'
                    && $this->is_liuchong($y_zhi, $this->bazi[8])
                )
                ||
                (
                    $this->shishen[$d_gan][$this->bazi[5]] == '比肩'
                    && $this->is_liuchong($y_zhi, $d_zhi)
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '冲比肩坐支：若本命或大运有比肩，流支冲比肩坐支',
                    'add' => 5
                ];
                $zhuanbian += 5;
            }
            // 5、双冲：流年与日柱或大运天克(五行相克【七杀||正财】)地冲+15，与月柱或时柱天克地冲+10
            if (
                (
                    in_array($this->shishen[$y_gan][$this->bazi[5]], ['正财', '七杀'])
                    && $this->is_liuchong($y_zhi, $this->bazi[6])
                )
                ||
                (
                    in_array($this->shishen[$y_gan][$d_gan], ['正财', '七杀'])
                    && $this->is_liuchong($y_zhi, $d_zhi)
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '双冲：流年与日柱或大运天克(五行相克【七杀||正财】)地冲',
                    'add' => 15
                ];
                $zhuanbian += 15;
            }
            if (
                (
                    in_array($this->shishen[$y_gan][$this->bazi[3]], ['正财', '七杀'])
                    && $this->is_liuchong($y_zhi, $this->bazi[4])
                )
                ||
                (
                    in_array($this->shishen[$y_gan][$this->bazi[7]], ['正财', '七杀'])
                    && $this->is_liuchong($y_zhi, $this->bazi[8])
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '双冲：流年与与月柱或时柱天克地冲',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 6、引冲：原局或大运有地支相冲，流支为相冲地支中的一个，+5
            if (
                (
                    $this->is_liuchong($this->bazi[2], $this->bazi[4])
                    && in_array($y_zhi, [$this->bazi[2], $this->bazi[4]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[2], $this->bazi[6])
                    && in_array($y_zhi, [$this->bazi[2], $this->bazi[6]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[2], $this->bazi[8])
                    && in_array($y_zhi, [$this->bazi[2], $this->bazi[8]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[2], $d_zhi)
                    && in_array($y_zhi, [$this->bazi[2], $d_zhi])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[4], $this->bazi[6])
                    && in_array($y_zhi, [$this->bazi[4], $this->bazi[6]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[4], $this->bazi[8])
                    && in_array($y_zhi, [$this->bazi[4], $this->bazi[8]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[4], $d_zhi)
                    && in_array($y_zhi, [$this->bazi[4], $d_zhi])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[6], $this->bazi[8])
                    && in_array($y_zhi, [$this->bazi[6], $this->bazi[8]])
                )
                ||
                (
                    $this->is_liuchong($this->bazi[6], $d_zhi)
                    && in_array($y_zhi, [$this->bazi[6], $d_zhi])
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '引冲：原局或大运有地支相冲，流支为相冲地支中的一个',
                    'add' => 5
                ];
                $zhuanbian += 5;
            }
            // 7、引刑：原局或大运有地支凑齐三刑，流支来冲其中之一+10
            if (
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[4], $this->bazi[6])
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[4], $this->bazi[8])
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[6], $this->bazi[8])
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[4], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[6], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[2], $this->bazi[8], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[2])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[4], $this->bazi[6], $this->bazi[8])
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[4], $this->bazi[6], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[4], $this->bazi[8], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[4])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
                ||
                (
                    $this->is_sanxing($this->bazi[6], $this->bazi[8], $d_zhi)
                    &&
                    (
                        $this->is_liuchong($y_zhi, $this->bazi[6])
                        || $this->is_liuchong($y_zhi, $this->bazi[8])
                        || $this->is_liuchong($y_zhi, $d_zhi)
                    )
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '引刑：原局或大运有地支凑齐三刑，流支来冲其中之一',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 8、运冲：原局某柱与大运干支形成正冲或双冲（正冲：天干一致，地支相冲；双冲：天干相克地支相冲），此时流支与该组相冲地支之一形成合、冲、拱、刑，+10
            if (
                (
                    (
                        $this->bazi[1] == $d_gan
                        || in_array($this->shishen[$this->bazi[1]][$d_gan], ['七杀', '正财'])
                    )
                    && $this->is_liuchong($this->bazi[2], $d_zhi)
                    &&
                    (
                        $this->is_liuhe($this->bazi[2], $y_zhi)
                        || $this->is_liuhe($d_zhi, $y_zhi)
                        || $this->is_liuchong($this->bazi[2], $y_zhi)
                        || $this->is_liuchong($d_zhi, $y_zhi)
                        || $this->is_gong($this->bazi[2], $y_zhi)
                        || $this->is_gong($d_zhi, $y_zhi)
                        || $this->is_xing($this->bazi[2], $y_zhi)
                        || $this->is_xing($d_zhi, $y_zhi)
                    )
                )
                ||
                (
                    (
                        $this->bazi[3] == $d_gan
                        || in_array($this->shishen[$this->bazi[3]][$d_gan], ['七杀', '正财'])
                    )
                    && $this->is_liuchong($this->bazi[4], $d_zhi)
                    &&
                    (
                        $this->is_liuhe($this->bazi[4], $y_zhi)
                        || $this->is_liuhe($d_zhi, $y_zhi)
                        || $this->is_liuchong($this->bazi[4], $y_zhi)
                        || $this->is_liuchong($d_zhi, $y_zhi)
                        || $this->is_gong($this->bazi[4], $y_zhi)
                        || $this->is_gong($d_zhi, $y_zhi)
                        || $this->is_xing($this->bazi[4], $y_zhi)
                        || $this->is_xing($d_zhi, $y_zhi)
                    )
                )
                ||
                (
                    (
                        $this->bazi[5] == $d_gan
                        || in_array($this->shishen[$this->bazi[5]][$d_gan], ['七杀', '正财'])
                    )
                    && $this->is_liuchong($this->bazi[6], $d_zhi)
                    &&
                    (
                        $this->is_liuhe($this->bazi[6], $y_zhi)
                        || $this->is_liuhe($d_zhi, $y_zhi)
                        || $this->is_liuchong($this->bazi[6], $y_zhi)
                        || $this->is_liuchong($d_zhi, $y_zhi)
                        || $this->is_gong($this->bazi[6], $y_zhi)
                        || $this->is_gong($d_zhi, $y_zhi)
                        || $this->is_xing($this->bazi[6], $y_zhi)
                        || $this->is_xing($d_zhi, $y_zhi)
                    )
                )
                ||
                (
                    (
                        $this->bazi[7] == $d_gan
                        || in_array($this->shishen[$this->bazi[7]][$d_gan], ['七杀', '正财'])
                    )
                    && $this->is_liuchong($this->bazi[8], $d_zhi)
                    &&
                    (
                        $this->is_liuhe($this->bazi[8], $y_zhi)
                        || $this->is_liuhe($d_zhi, $y_zhi)
                        || $this->is_liuchong($this->bazi[8], $y_zhi)
                        || $this->is_liuchong($d_zhi, $y_zhi)
                        || $this->is_gong($this->bazi[8], $y_zhi)
                        || $this->is_gong($d_zhi, $y_zhi)
                        || $this->is_xing($this->bazi[8], $y_zhi)
                        || $this->is_xing($d_zhi, $y_zhi)
                    )
                )
            ) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '运冲：原局某柱与大运干支形成正冲或双冲（正冲：天干一致，地支相冲；双冲：天干相克地支相冲），此时流支与该组相冲地支之一形成合、冲、拱、刑',
                    'add' => 10
                ];
                $zhuanbian += 10;
            }
            // 9、星盘补充：三限天王星刑冲合太阳+10，此时若木星与太阳成相+5；三限天王星六分三分太阳+5；行运天王星合四轴或刑冲合月亮+5
            $time_4_1 = $j . "-4-1";
            $time_10_1 = $j . "-10-1";
            $Third = new ThirdprogressedController();
            $Third->recode = $this->userinfo;
            $th_4_1 = json_decode($Third->get($time_4_1), true)['data']['planets'];
            $th_10_1 = json_decode($Third->get($time_10_1), true)['data']['planets'];
            $Transits = new TransitsController();
            $Transits->recode = $this->userinfo;
            $tr_4_1 = json_decode($Transits->get($time_4_1), true)['data'][1]['planets'];
            $tr_10_1 = json_decode($Transits->get($time_10_1), true)['data'][1]['planets'];
            $score_4_1 = 0;
            $score_10_1 = 0;
            if (isset($th_4_1[0]['phase']['0-7'])) {
                if (in_array($th_4_1[0]['phase']['0-7']['phase_e'], [0, 90, 180])) {
                    $score_4_1 += 10;
                    if (isset($th_4_1[0]['phase']['0-5'])) {
                        $score_4_1 += 5;
                    }
                } elseif (in_array($th_4_1[0]['phase']['0-7']['phase_e'], [60, 120])) {
                    $score_4_1 += 5;
                }

            }
            if (
                (
                    isset($tr_4_1[7]['phase']['7-' . ASC])
                    && in_array($tr_4_1[7]['phase']['7-' . ASC]['phase_e'], [0, 180])
                )
                ||
                (
                    isset($tr_4_1[7]['phase']['7-' . MC])
                    && in_array($tr_4_1[7]['phase']['7-' . MC]['phase_e'], [0, 180])
                )
                ||
                (
                    isset($tr_4_1[7]['phase']['7-1'])
                    && in_array($tr_4_1[7]['phase']['7-1']['phase_e'], [0, 90, 180])
                )
            ) {
                $score_4_1 += 5;
            }
            if (isset($th_10_1[0]['phase']['0-7'])) {
                if (in_array($th_10_1[0]['phase']['0-7']['phase_e'], [0, 90, 180])) {
                    $score_10_1 += 10;
                    if (isset($th_10_1[0]['phase']['0-5'])) {
                        $score_10_1 += 5;
                    }
                } elseif (in_array($th_10_1[0]['phase']['0-7']['phase_e'], [60, 120])) {
                    $score_10_1 += 5;
                }

            }
            if (
                (
                    isset($tr_10_1[7]['phase']['7-' . ASC])
                    && in_array($tr_10_1[7]['phase']['7-' . ASC]['phase_e'], [0, 180])
                )
                ||
                (
                    isset($tr_10_1[7]['phase']['7-' . MC])
                    && in_array($tr_10_1[7]['phase']['7-' . MC]['phase_e'], [0, 180])
                )
                ||
                (
                    isset($tr_10_1[7]['phase']['7-1'])
                    && in_array($tr_10_1[7]['phase']['7-1']['phase_e'], [0, 90, 180])
                )
            ) {
                $score_10_1 += 5;
            }
            if ($score_4_1 > $score_10_1) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '4月-1日',
                    'add' => 10
                ];
                $zhuanbian += $score_4_1;
            } elseif ($score_4_1 < $score_10_1) {
                $ret['zhuanbian'][$num]['condition'][] = [
                    'if' => '10月1日',
                    'add' => 10
                ];
                $zhuanbian += $score_10_1;
            }

            $ret['zhuanbian'][$num]['score'] = $zhuanbian;

            $num++;
        }
        return json(['code' => 200, 'data' => $ret, 'msg' => 'Success.']);
    }

    /**
     * 升职
     * @return json
     */
    public function get_shengzhi_to_json(Request $request)
    {
        $year = intval($request->input('year'));
        $end = intval($request->input('end'));// 计算的年数  如计算十年   $end=10;
        if (!$year) $year = intval(date("Y"));
        if ($end <= 0) $end = 0;

        $ret['bazi'] = implode($this->bazi);
        $ret['birth_sun_deg'] = $this->birth_sun_deg;
        $ret['sex'] = $this->sex;

        $st_year = date('Y', $this->st_time);
        $num = 0;
        for ($j = $year; $j <= $year + $end; $j++) {
            for ($i = $st_year; $i < $j; $i += 10) if ($j >= $i && $j < $i + 10) $st_year = $i;

            // 大运 干支
            $d_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($st_year)];
            $d_gan = mb_substr($d_gan_zhi, 0, 1, 'utf-8');// 大运天干
            $d_zhi = mb_substr($d_gan_zhi, 1, 1, 'utf-8');// 大运地支
            $dazhi = $this->canggan[$d_zhi][0];// 大运地支本气
            $y_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($j)];
            $y_gan = mb_substr($y_gan_zhi, 0, 1, 'utf-8');// 流年天干
            $y_zhi = mb_substr($y_gan_zhi, 1, 1, 'utf-8');// 流年地支
            $liuzhi = $this->canggan[$y_zhi][0];// 流年地支本气
            $rizhi = $this->canggan[$this->bazi[6]][0];// 本命地支本气

            $ret['shengzhi'][$num]['year'] = $j;
            $ret['shengzhi'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['shengzhi'][$num]['dayun_gan'] = $d_gan;
//            $ret['shengzhi'][$num]['dayun_zhi'] = $d_zhi;
            $ret['shengzhi'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['shengzhi'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['shengzhi'][$num]['liunian_gan'] = $y_gan;
//            $ret['shengzhi'][$num]['liunian_zhi'] = $y_zhi;
            $ret['shengzhi'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['shengzhi'][$num]['liunian_zhiqi'] = $liuzhi;

            $shengzhi = 0;
            // 1、流干或流支出现官杀+5（地支以本气论），若此时流支=日干禄或流干=比肩+5，若此时流支与日支相合+8相拱+5，若此时流支与运命某支（非日支）相合且不刑害日支+5
            if (
                $this->is_ygs($y_gan, $this->bazi[5], '官杀')
                || $this->is_ygs($liuzhi, $this->bazi[5], '官杀')
            ) {
                $ret['shengzhi'][$num]['condition'][] = [
                    'if' => '流干或流支出现官杀',
                    'add' => 5
                ];
                $shengzhi += 5;
                if (
                    $this->is_lushen($this->bazi[5], $y_zhi)
                    || $this->bazi[5] == $y_gan
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '流干或流支出现官杀,若此时流支=日干禄或流干=比肩',
                        'add' => 5
                    ];
                    $shengzhi += 5;
                }
                if ($this->is_liuhe($y_zhi, $this->bazi[6])) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '流干或流支出现官杀,若此时流支与日支相合',
                        'add' => 8
                    ];
                    $shengzhi += 8;
                }
                if ($this->is_gong($y_zhi, $this->bazi[6])) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '流干或流支出现官杀,若此时流支与日支相拱',
                        'add' => 8
                    ];
                    $shengzhi += 8;
                }
                if (
                    !$this->is_liuhai($y_zhi, $this->bazi[6])
                    && !$this->is_xing($y_zhi, $this->bazi[6])
                    &&
                    (
                        $this->is_liuhe($y_zhi, $this->bazi[2])
                        || $this->is_liuhe($y_zhi, $this->bazi[4])
                        || $this->is_liuhe($y_zhi, $this->bazi[8])
                        || $this->is_liuhe($y_zhi, $d_zhi)
                    )
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '流干或流支出现官杀,若此时流支与运命某支（非日支）相合且不刑害日支',
                        'add' => 5
                    ];
                    $shengzhi += 5;
                }
            }

            // 2、原局天干有官杀或月支日支为官杀且官杀衰弱（低于20%）且日干助力强旺（比劫+印高于40%），流干或流支为官杀+10
            // 3、原局天干有官杀或月支日支为官杀且官杀强旺（高于20%）且日干助力衰弱（比劫+印低于40%），流干或流支为正印+10
            $wx_perc = $this->get_wuxing_percent();// 获取五行百分比
            $rigan_wx = $this->wuxing[$this->bazi[5]];// 日干五行属性
            $wx_beike = ['木' => '金', '土' => '木', '水' => '土', '火' => '水', '金' => '火'];// 五行被克关系
            $wx_ke = ['金' => '木', '木' => '土', '土' => '水', '水' => '火', '火' => '金'];// 五行克关系
            $gs_wx = $wx_beike[$rigan_wx];// 官杀五行属性 克我
            $c_wx = $wx_ke[$rigan_wx];// 财星五行属性 我克
            $bj_wx = $rigan_wx;// 比劫五行属性 同我
            $wx_beisheng = ['土' => '金', '金' => '水', '水' => '木', '木' => '火', '火' => '土'];// 五行被生关系
            $y_wx = $wx_beisheng[$rigan_wx];// 印五行属性 生我
            $gs_prec = $wx_perc[$gs_wx];// 官杀五行百分比
            $c_prec = $wx_perc[$c_wx];// 财星五行百分比
            $bj_prec = $wx_perc[$bj_wx];// 比劫五行百分比
            $y_prec = $wx_perc[$y_wx];// 印五行百分比
            if (
                $this->is_ygs($this->bazi[1], $this->bazi[5], '官杀')
                || $this->is_ygs($this->bazi[3], $this->bazi[5], '官杀')
                || $this->is_ygs($this->bazi[7], $this->bazi[5], '官杀')
                || $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '官杀')
                || $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '官杀')
            ) {
                if (
                    (
                        $this->is_ygs($y_gan, $this->bazi[5], '官杀')
                        || $this->is_ygs($liuzhi, $this->bazi[5], '官杀')
                    )
                    && $gs_prec < 20 && ($bj_prec + $y_prec) > 40
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '原局天干有官杀或月支日支为官杀且官杀衰弱（低于20%）且日干助力强旺（比劫+印高于40%），流干或流支为官杀',
                        'add' => 10
                    ];
                    $shengzhi += 10;
                }
                if (
                    (
                        $this->shishen[$y_gan][$this->bazi[5]] == '正印'
                        || $this->shishen[$liuzhi][$this->bazi[5]] == '正印'
                    )
                    && $gs_prec > 20 && ($bj_prec + $y_prec) < 40
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '原局天干有官杀或月支日支为官杀且官杀强旺（高于20%）且日干助力衰弱（比劫+印低于40%），流干或流支为正印',
                        'add' => 10
                    ];
                    $shengzhi += 10;
                }
            }
            // 4、本命天干无伤官，运干是正官，若流干非伤官非七杀，+5，若此时运支为日干禄+6，若此时运支合拱日支+6
            // 5、本命天干有伤官，运干是正官，若流干与伤官相合或流干为正印，+10，若此时运支为日干禄+6，若此时运支合拱日支+6
            if (
                (
                    $this->shishen[$this->bazi[1]][$this->bazi[5]] == '伤官'
                    || $this->shishen[$this->bazi[3]][$this->bazi[5]] == '伤官'
                    || $this->shishen[$this->bazi[7]][$this->bazi[5]] == '伤官'
                )
                && $this->shishen[$d_gan][$this->bazi[5]] == '伤官'
            ) {
                if (
                    !$this->shishen[$y_gan][$this->bazi[5]] == '伤官'
                    && !$this->shishen[$y_gan][$this->bazi[5]] == '七杀'
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '本命天干无伤官，运干是正官，若流干非伤官非七杀',
                        'add' => 5
                    ];
                    $shengzhi += 5;
                    if ($this->is_lushen($this->bazi[5], $y_zhi)) {
                        $ret['shengzhi'][$num]['condition'][] = [
                            'if' => '本命天干无伤官，运干是正官，若流干非伤官非七杀,若此时运支为日干禄',
                            'add' => 6
                        ];
                        $shengzhi += 6;
                    }
                    if (
                        $this->is_liuhe($y_zhi, $this->bazi[6])
                        || $this->is_gong($y_zhi, $this->bazi[6])
                    ) {
                        $ret['shengzhi'][$num]['condition'][] = [
                            'if' => '本命天干无伤官，运干是正官，若流干非伤官非七杀,若此时运支合拱日支',
                            'add' => 6
                        ];
                        $shengzhi += 6;
                    }
                }
                if (
                    (
                        (
                            $this->shishen[$this->bazi[1]][$this->bazi[5]] == '伤官'
                            && $this->is_wuhe($y_gan, $this->bazi[1])
                        )
                        ||
                        (
                            $this->shishen[$this->bazi[3]][$this->bazi[5]] == '伤官'
                            && $this->is_wuhe($y_gan, $this->bazi[3])
                        )
                        ||
                        (
                            $this->shishen[$this->bazi[7]][$this->bazi[5]] == '伤官'
                            && $this->is_wuhe($y_gan, $this->bazi[7])
                        )
                    )
                    || $this->shishen[$y_gan][$this->bazi[5]] == '正印'
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '本命天干有伤官，运干是正官，若流干与伤官相合或流干为正印',
                        'add' => 10
                    ];
                    $shengzhi += 10;
                    if ($this->is_lushen($this->bazi[5], $y_zhi)) {
                        $ret['shengzhi'][$num]['condition'][] = [
                            'if' => '本命天干有伤官，运干是正官，若流干与伤官相合或流干为正印,若此时运支为日干禄',
                            'add' => 6
                        ];
                        $shengzhi += 6;
                    }
                    if (
                        $this->is_liuhe($y_zhi, $this->bazi[6])
                        || $this->is_gong($y_zhi, $this->bazi[6])
                    ) {
                        $ret['shengzhi'][$num]['condition'][] = [
                            'if' => '本命天干有伤官，运干是正官，若流干与伤官相合或流干为正印,若此时运支合拱日支',
                            'add' => 6
                        ];
                        $shengzhi += 6;
                    }
                }
            }
            // 6、若原局天干有七杀，且官杀力量大于20%，流干与七杀相合或为食神+8；若此时七杀位于运干+10
            if (
                $this->shishen[$this->bazi[1]][$this->bazi[5]] == '七杀'
                || $this->shishen[$this->bazi[3]][$this->bazi[5]] == '七杀'
                || $this->shishen[$this->bazi[7]][$this->bazi[5]] == '七杀'
            ) {
                if ($gs_prec > 20) {
                    if (
                        (
                            (
                                $this->shishen[$this->bazi[1]][$this->bazi[5]] == '七杀'
                                && $this->is_wuhe($y_gan, $this->bazi[1])
                            )
                            ||
                            (
                                $this->shishen[$this->bazi[3]][$this->bazi[5]] == '七杀'
                                && $this->is_wuhe($y_gan, $this->bazi[3])
                            )
                            ||
                            (
                                $this->shishen[$this->bazi[7]][$this->bazi[5]] == '七杀'
                                && $this->is_wuhe($y_gan, $this->bazi[7])
                            )
                        )
                        || $this->shishen[$y_gan][$this->bazi[5]] == '食神'
                    ) {
                        $ret['shengzhi'][$num]['condition'][] = [
                            'if' => '若原局天干有七杀，且官杀力量大于20%，流干与七杀相合或为食神',
                            'add' => 8
                        ];
                        $shengzhi += 8;
                        if ($this->shishen[$d_gan][$this->bazi[5]] == '七杀') {
                            $ret['shengzhi'][$num]['condition'][] = [
                                'if' => '若原局天干有七杀，且官杀力量大于20%，流干与七杀相合或为食神,若此时七杀位于运干',
                                'add' => 10
                            ];
                            $shengzhi += 10;
                        }
                    }
                }
            }
            // 7、若原局天干有正官有偏印，且财+官<印+比，流干合偏印+8
            if (
                (
                    $this->shishen[$this->bazi[1]][$this->bazi[5]] == '正官'
                    || $this->shishen[$this->bazi[3]][$this->bazi[5]] == '正官'
                    || $this->shishen[$this->bazi[7]][$this->bazi[5]] == '正官'
                )
                &&
                (
                    $this->shishen[$this->bazi[1]][$this->bazi[5]] == '偏印'
                    || $this->shishen[$this->bazi[3]][$this->bazi[5]] == '偏印'
                    || $this->shishen[$this->bazi[7]][$this->bazi[5]] == '偏印'
                )
                && ($c_prec + $gs_prec) < ($y_prec + $bj_prec)
            ) {
                if (
                    (
                        $this->shishen[$this->bazi[1]][$this->bazi[5]] == '偏印'
                        && $this->is_wuhe($this->bazi[1], $y_gan)
                    )
                    ||
                    (
                        $this->shishen[$this->bazi[3]][$this->bazi[5]] == '偏印'
                        && $this->is_wuhe($this->bazi[3], $y_gan)
                    )
                    ||
                    (
                        $this->shishen[$this->bazi[7]][$this->bazi[5]] == '偏印'
                        && $this->is_wuhe($this->bazi[7], $y_gan)
                    )
                ) {
                    $ret['shengzhi'][$num]['condition'][] = [
                        'if' => '若原局天干有正官有偏印，且财+官<印+比，流干合偏印',
                        'add' => 8
                    ];
                    $shengzhi += 8;
                }
            }
            // 8、星盘补充：三限日木成相+6，木在10宫+4
            $time_4_1 = $j . "-4-1";
            $time_10_1 = $j . "-10-1";
            $Third = new ThirdprogressedController();
            $Third->recode = $this->userinfo;
            $th_4_1 = json_decode($Third->get($time_4_1), true)['data']['planets'];
            $th_10_1 = json_decode($Third->get($time_10_1), true)['data']['planets'];
            $score_4_1 = 0;
            $score_10_1 = 0;
            if (isset($th_4_1[0]['phase']['0-5'])) $score_4_1 += 6;
            if ($th_4_1[5]['in_house_id'] == 10) $score_4_1 += 10;
            if (isset($th_10_1[0]['phase']['0-5'])) $score_10_1 += 6;
            if ($th_10_1[5]['in_house_id'] == 10) $score_10_1 += 10;

            if ($score_4_1 > $score_10_1) {
                $ret['shengzhi'][$num]['condition'][] = [
                    'if' => '4月-1日',
                    'add' => $score_4_1
                ];
                $shengzhi += $score_4_1;
            } elseif ($score_4_1 < $score_10_1) {
                $ret['shengzhi'][$num]['condition'][] = [
                    'if' => '10月1日',
                    'add' => $score_10_1
                ];
                $shengzhi += $score_10_1;
            }
            $ret['shengzhi'][$num]['score'] = $shengzhi;
            $num++;
        }
        return json(['code' => 200, 'data' => $ret, 'msg' => 'Success.']);
    }

    /**
     * 进财
     * @return json
     */
    public function get_jincai_to_json(Request $request)
    {
        $year = intval($request->input('year'));
        $end = intval($request->input('end'));// 计算的年数  如计算十年   $end=10;
        if (!$year) $year = intval(date("Y"));
        if ($end <= 0) $end = 0;

        $ret['bazi'] = implode($this->bazi);
        $ret['birth_sun_deg'] = $this->birth_sun_deg;
        $ret['sex'] = $this->sex;

        $st_year = date('Y', $this->st_time);
        $num = 0;
        for ($j = $year; $j <= $year + $end; $j++) {
            for ($i = $st_year; $i < $j; $i += 10) if ($j >= $i && $j < $i + 10) $st_year = $i;

            // 大运 干支
            $d_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($st_year)];
            $d_gan = mb_substr($d_gan_zhi, 0, 1, 'utf-8');// 大运天干
            $d_zhi = mb_substr($d_gan_zhi, 1, 1, 'utf-8');// 大运地支
            $dazhi = $this->canggan[$d_zhi][0];// 大运地支本气
            $y_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($j)];
            $y_gan = mb_substr($y_gan_zhi, 0, 1, 'utf-8');// 流年天干
            $y_zhi = mb_substr($y_gan_zhi, 1, 1, 'utf-8');// 流年地支
            $liuzhi = $this->canggan[$y_zhi][0];// 流年地支本气
            $rizhi = $this->canggan[$this->bazi[6]][0];// 本命地支本气

            $ret['jincai'][$num]['year'] = $j;
            $ret['jincai'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['jincai'][$num]['dayun_gan'] = $d_gan;
//            $ret['jincai'][$num]['dayun_zhi'] = $d_zhi;
            $ret['jincai'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['jincai'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['jincai'][$num]['liunian_gan'] = $y_gan;
//            $ret['jincai'][$num]['liunian_zhi'] = $y_zhi;
            $ret['jincai'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['jincai'][$num]['liunian_zhiqi'] = $liuzhi;

            $jincai = 0;

            // 1、流干或流支本气为财星+10；若此时流支=日干禄或流干=比肩+5；若此时流支=本命或大运中的财支或财干的禄+5；若此时流干=本命或大运中的财干或财支的反禄（反禄：若某地支是某天干的禄，该天干是该地支的反禄）+5
            if (
                $this->is_ygs($y_gan, $this->bazi[5], '财')
                || $this->is_ygs($liuzhi, $this->bazi[5], '财')
            ) {
                $ret['jincai'][$num]['condition'][] = [
                    'if' => '流干或流支本气为财星',
                    'add' => 10
                ];
                $jincai += 10;
                if (
                    $this->is_lushen($this->bazi[5], $y_gan)
                    || $this->bazi[5] == $y_gan
                ) {
                    $ret['jincai'][$num]['condition'][] = [
                        'if' => '流干或流支本气为财星,若此时流支=日干禄或流干=比肩',
                        'add' => 5
                    ];
                    $jincai += 5;
                }
                if (
                    (
                        $this->is_ygs($this->bazi[1], $this->bazi[5], '财')
                        && $this->is_lushen($this->bazi[1], $y_zhi)
                    )
                    ||
                    (
                        $this->is_ygs($this->bazi[3], $this->bazi[5], '财')
                        && $this->is_lushen($this->bazi[3], $y_zhi)
                    )
                    ||
                    (
                        $this->is_ygs($this->bazi[7], $this->bazi[5], '财')
                        && $this->is_lushen($this->bazi[3], $y_zhi)
                    )
                    ||
                    (
                        $this->is_ygs($d_gan, $this->bazi[5], '财')
                        && $this->is_lushen($d_gan, $y_zhi)
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '财')
                        && $y_zhi == $this->bazi[2]
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '财')
                        && $y_zhi == $this->bazi[4]
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '财')
                        && $y_zhi == $this->bazi[6]
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '财')
                        && $y_zhi == $this->bazi[8]
                    )
                ) {
                    $ret['jincai'][$num]['condition'][] = [
                        'if' => '流干或流支本气为财星,若此时流支=本命或大运中的财支或财干的禄',
                        'add' => 5
                    ];
                    $jincai += 5;
                }
                if (
                    (
                        $this->is_ygs($this->bazi[1], $this->bazi[5], '财')
                        && $this->bazi[1] == $y_gan
                    )
                    ||
                    (
                        $this->is_ygs($this->bazi[3], $this->bazi[5], '财')
                        && $this->bazi[3] == $y_gan
                    )
                    ||
                    (
                        $this->is_ygs($this->bazi[7], $this->bazi[5], '财')
                        && $this->bazi[7] == $y_gan
                    )
                    ||
                    (
                        $this->is_ygs($d_gan, $this->bazi[5], '财')
                        && $d_gan == $y_gan
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '财')
                        && $this->is_lushen($y_gan, $this->bazi[2])
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '财')
                        && $this->is_lushen($y_gan, $this->bazi[4])
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '财')
                        && $this->is_lushen($y_gan, $this->bazi[6])
                    )
                    ||
                    (
                        $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '财')
                        && $this->is_lushen($y_gan, $this->bazi[8])
                    )
                ) {
                    $ret['jincai'][$num]['condition'][] = [
                        'if' => '流干或流支本气为财星,若此时流干=本命或大运中的财干或财支的反禄（反禄：若某地支是某天干的禄，该天干是该地支的反禄）',
                        'add' => 5
                    ];
                    $jincai += 5;
                }
            }
            // 2、大运+原局天干有财星有劫财，流干合劫财或流干=正官  +10
            if (
                (
                    $this->is_ygs($this->bazi[1], $this->bazi[5], '财')
                    || $this->is_ygs($this->bazi[3], $this->bazi[5], '财')
                    || $this->is_ygs($this->bazi[7], $this->bazi[5], '财')
                    || $this->is_ygs($d_gan, $this->bazi[5], '财')
                )
                &&
                (
                    (
                        $this->shishen[$this->bazi[1]][$this->bazi[5]] == '劫财'
                        &&
                        (
                            $this->is_wuhe($y_gan, $this->bazi[1])
                            || $this->shishen[$y_gan][$this->bazi[5]] == '正官'
                        )
                    )
                    ||
                    (
                        $this->shishen[$this->bazi[3]][$this->bazi[5]] == '劫财'
                        &&
                        (
                            $this->is_wuhe($y_gan, $this->bazi[3])
                            || $this->shishen[$y_gan][$this->bazi[5]] == '正官'
                        )
                    )
                    ||
                    (
                        $this->shishen[$this->bazi[7]][$this->bazi[5]] == '劫财'
                        &&
                        (
                            $this->is_wuhe($y_gan, $this->bazi[7])
                            || $this->shishen[$y_gan][$this->bazi[5]] == '正官'
                        )
                    )
                    ||
                    (
                        $this->shishen[$d_gan][$this->bazi[5]] == '劫财'
                        &&
                        (
                            $this->is_wuhe($y_gan, $d_gan)
                            || $this->shishen[$y_gan][$this->bazi[5]] == '正官'
                        )
                    )
                )
            ) {
                $ret['jincai'][$num]['condition'][] = [
                    'if' => '大运+原局天干有财星有劫财，流干合劫财或流干=正官',
                    'add' => 10
                ];
                $jincai += 10;
            }
            // 3、大运天干为财或地支为财，若流干不是劫财且不是七杀+6
            if (
                $this->is_ygs($d_gan, $this->bazi[5], '财')
                || $this->is_ygs($this->canggan[$d_zhi][0], $this->bazi[5], '财')
            ) {
                if (
                    $this->shishen[$y_gan][$this->bazi[5]] == '劫财'
                    && $this->shishen[$y_gan][$this->bazi[5]] == '七杀'
                ) {
                    $ret['jincai'][$num]['condition'][] = [
                        'if' => '大运天干为财或地支为财，若流干不是劫财且不是七杀',
                        'add' => 6
                    ];
                    $jincai += 6;
                }
            }
            // 4、星盘补充：三限日木或金木成相+6，木在2宫或土在2宫+6
            $time_4_1 = $j . "-4-1";
            $time_10_1 = $j . "-10-1";
            $Third = new ThirdprogressedController();
            $Third->recode = $this->userinfo;
            $th_4_1 = json_decode($Third->get($time_4_1), true)['data']['planets'];
            $th_10_1 = json_decode($Third->get($time_10_1), true)['data']['planets'];
            $score_4_1 = 0;
            $score_10_1 = 0;
            if (isset($th_4_1[0]['phase']['0-5']) || isset($th_4_1[3]['phase']['3-5']))
                $score_4_1 += 6;
            if ($th_4_1[5]['in_house_id'] == 2 || $th_4_1[6]['in_house_id'] == 2)
                $score_4_1 += 6;
            if (isset($th_10_1[0]['phase']['0-5']) || isset($th_10_1[3]['phase']['3-5']))
                $score_10_1 += 6;
            if ($th_10_1[5]['in_house_id'] == 2 || $th_10_1[6]['in_house_id'] == 2)
                $score_10_1 += 6;

            if ($score_4_1 > $score_10_1) {
                $ret['jincai'][$num]['condition'][] = [
                    'if' => '4月-1日',
                    'add' => $score_4_1
                ];
                $jincai += $score_4_1;
            } elseif ($score_4_1 < $score_10_1) {
                $ret['jincai'][$num]['condition'][] = [
                    'if' => '10月1日',
                    'add' => $score_10_1
                ];
                $jincai += $score_10_1;
            }
            $ret['jincai'][$num]['score'] = $jincai;

            $num++;
        }

        return json(['code' => 200, 'data' => $ret, 'msg' => 'Success.']);
    }

    /**
     * 父母
     * @return mixed
     */
    public function get_fumu_to_json(Request $request)
    {
        $year = intval($request->input('year'));
        $end = intval($request->input('end'));// 计算的年数  如计算十年   $end=10;
        if (!$year) $year = intval(date("Y"));
        if ($end <= 0) $end = 0;

        $ret['bazi'] = implode($this->bazi);
        $ret['birth_sun_deg'] = $this->birth_sun_deg;
        $ret['sex'] = $this->sex;

        $st_year = date('Y', $this->st_time);
        $num = 0;
        for ($j = $year; $j <= $year + $end; $j++) {
            for ($i = $st_year; $i < $j; $i += 10) if ($j >= $i && $j < $i + 10) $st_year = $i;

            // 大运 干支
            $d_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($st_year)];
            $d_gan = mb_substr($d_gan_zhi, 0, 1, 'utf-8');// 大运天干
            $d_zhi = mb_substr($d_gan_zhi, 1, 1, 'utf-8');// 大运地支
            $dazhi = $this->canggan[$d_zhi][0];// 大运地支本气
            $y_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($j)];
            $y_gan = mb_substr($y_gan_zhi, 0, 1, 'utf-8');// 流年天干
            $y_zhi = mb_substr($y_gan_zhi, 1, 1, 'utf-8');// 流年地支
            $liuzhi = $this->canggan[$y_zhi][0];// 流年地支本气
            $rizhi = $this->canggan[$this->bazi[6]][0];// 本命地支本气

            $ret['fumu'][$num]['year'] = $j;
            $ret['fumu'][$num]['transits_year'] = $st_year;// 所属大运
//            $ret['fumu'][$num]['dayun_gan'] = $d_gan;
//            $ret['fumu'][$num]['dayun_zhi'] = $d_zhi;
            $ret['fumu'][$num]['dayun_gan_zhi'] = $d_gan . $d_zhi;
            $ret['fumu'][$num]['dayun_zhiqi'] = $dazhi;
//            $ret['fumu'][$num]['liunian_gan'] = $y_gan;
//            $ret['fumu'][$num]['liunian_zhi'] = $y_zhi;
            $ret['fumu'][$num]['liunian_gan_zhi'] = $y_gan . $y_zhi;
            $ret['fumu'][$num]['liunian_zhiqi'] = $liuzhi;

            $fumu = 0;
            // 1、流年地支冲本命年支+10，若此时为天克地冲+8；若此时大运天干为财星或印星+6
            if ($this->is_liuchong($y_zhi, $this->bazi[2])) {
                $ret['fumu'][$num]['condition'][] = [
                    'if' => '流年地支冲本命年支',
                    'add' => 6
                ];
                $fumu += 6;
                if (
                    in_array($this->shishen[$y_gan][$this->bazi[1]], ['正财', '七杀'])
                    && $this->is_liuchong($y_zhi, $this->bazi[2])
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流年地支冲本命年支,若此时为天克地冲',
                        'add' => 8
                    ];
                    $fumu += 8;
                }
                if (
                    $this->is_ygs($d_gan, $this->bazi[5], '财')
                    || $this->is_ygs($d_gan, $this->bazi[5], '印')
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流年地支冲本命年支,若此时大运天干为财星或印星',
                        'add' => 8
                    ];
                    $fumu += 6;
                }
            }
            // 2、流年地支刑穿本命年支+10，若此时为干合支穿+8；若此时运干为财星或印星+6
            if (
                $this->is_xing($y_zhi, $this->bazi[2])
                || $this->is_liuhai($y_zhi, $this->bazi[2])
            ) {
                $ret['fumu'][$num]['condition'][] = [
                    'if' => '流年地支刑穿本命年支',
                    'add' => 10
                ];
                $fumu += 10;
                if (
                    $this->is_wuhe($y_gan, $this->bazi[1])
                    && $this->is_liuhai($y_zhi, $this->bazi[2])
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流年地支刑穿本命年支,若此时为干合支穿',
                        'add' => 8
                    ];
                    $fumu += 8;
                }
                if (
                    $this->is_ygs($d_gan, $this->bazi[5], '财')
                    || $this->is_ygs($d_gan, $this->bazi[5], '印')
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流年地支冲本命年支,若此时大运天干为财星或印星',
                        'add' => 6
                    ];
                    $fumu += 6;
                }
            }
            // 3、流干的禄是年支，流支刑冲穿原局或大运的财支或财干坐支+14
            // 4、流干的禄是年支，流支刑冲穿原局或大运的印支或印干坐支+14
            if (
            $this->is_lushen($y_gan, $this->bazi[2])
            ) {
                if (
                    (
                        (
                            $this->is_ygs($this->bazi[1], $this->bazi[5], '财')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[2])
                            || $this->is_liuchong($y_zhi, $this->bazi[2])
                            || $this->is_liuhai($y_zhi, $this->bazi[2])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($this->bazi[3], $this->bazi[5], '财')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[4])
                            || $this->is_liuchong($y_zhi, $this->bazi[4])
                            || $this->is_liuhai($y_zhi, $this->bazi[4])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($this->bazi[7], $this->bazi[5], '财')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[8])
                            || $this->is_liuchong($y_zhi, $this->bazi[8])
                            || $this->is_liuhai($y_zhi, $this->bazi[8])
                        )
                    )
                    &&
                    (
                        $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '财')
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[6])
                            || $this->is_liuchong($y_zhi, $this->bazi[6])
                            || $this->is_liuhai($y_zhi, $this->bazi[6])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($d_gan, $this->bazi[5], '财')
                            ||
                            $this->is_ygs($dazhi, $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $d_zhi)
                            || $this->is_liuchong($y_zhi, $d_zhi)
                            || $this->is_liuhai($y_zhi, $d_zhi)
                        )
                    )
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流干的禄是年支，流支刑冲穿原局或大运的财支或财干坐支',
                        'add' => 14
                    ];
                    $fumu += 14;
                }
                if (
                    (
                        (
                            $this->is_ygs($this->bazi[1], $this->bazi[5], '印')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[2]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[2])
                            || $this->is_liuchong($y_zhi, $this->bazi[2])
                            || $this->is_liuhai($y_zhi, $this->bazi[2])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($this->bazi[3], $this->bazi[5], '印')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[4]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[4])
                            || $this->is_liuchong($y_zhi, $this->bazi[4])
                            || $this->is_liuhai($y_zhi, $this->bazi[4])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($this->bazi[7], $this->bazi[5], '印')
                            ||
                            $this->is_ygs($this->canggan[$this->bazi[8]][0], $this->bazi[5], '财')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[8])
                            || $this->is_liuchong($y_zhi, $this->bazi[8])
                            || $this->is_liuhai($y_zhi, $this->bazi[8])
                        )
                    )
                    &&
                    (
                        $this->is_ygs($this->canggan[$this->bazi[6]][0], $this->bazi[5], '印')
                        &&
                        (
                            $this->is_xing($y_zhi, $this->bazi[6])
                            || $this->is_liuchong($y_zhi, $this->bazi[6])
                            || $this->is_liuhai($y_zhi, $this->bazi[6])
                        )
                    )
                    &&
                    (
                        (
                            $this->is_ygs($d_gan, $this->bazi[5], '印')
                            ||
                            $this->is_ygs($dazhi, $this->bazi[5], '印')
                        )
                        &&
                        (
                            $this->is_xing($y_zhi, $d_zhi)
                            || $this->is_liuchong($y_zhi, $d_zhi)
                            || $this->is_liuhai($y_zhi, $d_zhi)
                        )
                    )
                ) {
                    $ret['fumu'][$num]['condition'][] = [
                        'if' => '流干的禄是年支，流支刑冲穿原局或大运的印支或印干坐支',
                        'add' => 14
                    ];
                    $fumu += 14;
                }

            }
            $ret['fumu'][$num]['score'] = $fumu;

            $num++;
        }
        return json(['code' => 200, 'data' => $ret, 'msg' => 'Success.']);
    }

    /**
     * 桃花
     * @param int $year
     * @param bool $self
     * @param string $setting
     * @return int
     * @throws \app\common\lib\exception\ApiException
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function getTaohua($year = 2017, $self = false, $setting = 'user')
    {
        $this->initload($self, $setting);// 八字等信息初始化
        $st_year = date('Y', $this->st_time);
        for ($i = $st_year; $i < $year; $i += 10) if ($year >= $i && $year < $i + 10) $st_year = $i;


        // 大运 干支
        $d_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($st_year)];
        $d_gan = mb_substr($d_gan_zhi, 0, 1, 'utf-8');// 大运天干
        $d_zhi = mb_substr($d_gan_zhi, 1, 1, 'utf-8');// 大运地支
        $dazhi = $this->canggan[$d_zhi][0];// 大运地支本气

        $taohua = 0;
        $y_gan_zhi = $this->Chinese_era[$this->getYearStemBranche($year)];
        $y_gan = mb_substr($y_gan_zhi, 0, 1, 'utf-8');// 流年天干
        $y_zhi = mb_substr($y_gan_zhi, 1, 1, 'utf-8');// 流年地支
        $liuzhi = $this->canggan[$y_zhi][0];// 流年地支本气
        $rizhi = $this->canggan[$this->bazi[6]][0];// 本命地支本气
        // 1.干财官
        if (
            // 男命，流年天干为正财或偏财【+15】
            ($this->sex == 1 && ($this->shishen[$y_gan][$this->bazi[5]] == '正财'
                    || $this->shishen[$y_gan][$this->bazi[5]] == '偏财'))
            ||
            // 女命，流年天干为七杀或正官【+15】
            ($this->sex == 2 && ($this->shishen[$y_gan][$this->bazi[5]] == '七杀'
                    || $this->shishen[$y_gan][$this->bazi[5]] == '正官'))
        ) {
            $taohua += 15;
            // 此时地支为日干之禄【+15】
            if ($this->is_lushen($this->bazi[5], $y_zhi)) {
                $taohua += 15;
            }
            // 此时地支为日支【+12】
            if ($this->bazi[6] == $y_zhi) {
                $taohua += 12;
            }
        }
        // 2.支财官
        if (
            // 男命，流年地支为正财或偏财【+12】
            ($this->sex == 1 && ($this->shishen[$liuzhi][$this->bazi[5]] == '正财'
                    || $this->shishen[$liuzhi][$this->bazi[5]] == '偏财'))
            ||
            // 女命，流年地支为七杀或正官【+12】
            ($this->sex == 2 && ($this->shishen[$liuzhi][$this->bazi[5]] == '七杀'
                    || $this->shishen[$liuzhi][$this->bazi[5]] == '正官'))
        ) {
            $taohua += 12;
            // 此时天干为比肩【+13】
            if ($this->shishen[$y_gan][$this->bazi[5]] == '比肩') {
                $taohua += 13;
            }
            // 此时天干与日干相合【+15】
            if ($this->is_liuhe($y_gan, $this->bazi[5])) {
                $taohua += 15;
            }
        }
        // 3.天地合 流年地支与日支合【+8】
        if ($this->is_liuhe($y_zhi, $this->bazi[6])) {
            $taohua += 8;
            // 此时天干也与日干合【+8】
            if ($this->is_liuhe($y_gan, $this->bazi[5])) {
                $taohua += 8;
            }
            // 此时日支为财（男）或官杀（女）【+8】
            if (
                // 此时日支为财（男）【+8】
                ($this->sex == 1 && ($this->shishen[$rizhi][$this->bazi[5]] == '正财'
                        || $this->shishen[$rizhi][$this->bazi[5]] == '偏财'))
                ||
                // 此时日支为官杀（女）【+8】
                ($this->sex == 2 && ($this->shishen[$rizhi][$this->bazi[5]] == '七杀'
                        || $this->shishen[$rizhi][$this->bazi[5]] == '正官'))
            ) {
                $taohua += 8;
            }
        }
        // 4.冲日支
        if ($this->is_liuchong($y_zhi, $this->bazi[6])) {
            if (
                // 此时流支为财（男）【+7】
                ($this->sex == 1 && ($this->shishen[$liuzhi][$this->bazi[5]] == '正财'
                        || $this->shishen[$liuzhi][$this->bazi[5]] == '偏财'))
                ||
                // 此时流支为官杀（女）【+7】
                ($this->sex == 2 && ($this->shishen[$liuzhi][$this->bazi[5]] == '七杀'
                        || $this->shishen[$liuzhi][$this->bazi[5]] == '正官'))
            ) {
                $taohua += 7;
            }
            if (
                // 此时日支为财（男）【+7】
                ($this->sex == 1 && ($this->shishen[$rizhi][$this->bazi[5]] == '正财'
                        || $this->shishen[$rizhi][$this->bazi[5]] == '偏财'))
                ||
                // 此时日支为官杀（女）【+7】
                ($this->sex == 2 && ($this->shishen[$rizhi][$this->bazi[5]] == '七杀'
                        || $this->shishen[$rizhi][$this->bazi[5]] == '正官'))
            ) {
                $taohua += 7;
            }
            // 此时流干为比肩【+7】
            if ($this->shishen[$y_gan][$this->bazi[5]] == '比肩') {
                $taohua += 7;
            }
            // 此时日支在命局或大运中被合【+7】   ##################  大运未完成  一大运  十流年
            if (
                $this->is_liuhe($this->bazi[6], $this->bazi[2])
                || $this->is_liuhe($this->bazi[6], $this->bazi[4])
                || $this->is_liuhe($this->bazi[6], $this->bazi[8])
            ) {
                $taohua += 7;
            }
            // 此时日支为辰戌丑未【+3】
            if (in_array($this->bazi[6], ['辰', '戌', '丑', '未'])) {
                $taohua += 3;
            }
        }
        // 5.桃花年：流年地支为日支所起的桃花【+5】
        if ($this->is_taohua($this->bazi[6], $y_zhi)) {
            $taohua += 5;
        }
        // 流年地支为年支所起的桃花且流年地支在本命中或大运存在【+5】
        if (
            $this->is_taohua($this->bazi[2], $y_zhi)
            && (
                $this->bazi[4] == $y_zhi
                || $this->bazi[4] == $y_zhi
                || $this->bazi[4] == $y_zhi
                || $d_zhi == $y_zhi
            )
        ) {
            $taohua += 5;
        }
        // 6.合留 若原命局地支或大运地支本气财星（男）或本气官星（女）被冲或穿，流年地支来合【+8】
        $temp_arr = [$this->bazi[2], $this->bazi[4], $this->bazi[6], $this->bazi[8], $d_zhi];
        // 本命年支
        if (
            // 流年地支来合
            $this->is_liuhe($y_zhi, $this->bazi[2]) &&
            // 被冲或穿
            ($this->liuchong($this->bazi[2], $temp_arr) || $this->liuhai($this->bazi[2], $temp_arr))

        ) {
            if (
                ($this->sex == 1 &&
                    in_array($this->shishen[$this->canggan[$this->bazi[2]][0]][$this->bazi[5]], ['偏财', '正财']))
                ||
                ($this->sex == 2 &&
                    in_array($this->shishen[$this->canggan[$this->bazi[2]][0]][$this->bazi[5]], ['七杀', '正官']))
            ) {
                $taohua += 8;
            }
        } // 本命月支
        elseif (
            // 流年地支来合
            $this->is_liuhe($y_zhi, $this->bazi[4]) &&
            // 被冲或穿
            ($this->liuchong($this->bazi[4], $temp_arr) || $this->liuhai($this->bazi[4], $temp_arr))

        ) {
            if (
                ($this->sex == 1 &&
                    in_array($this->shishen[$this->canggan[$this->bazi[4]][0]][$this->bazi[5]], ['偏财', '正财']))
                ||
                ($this->sex == 2 &&
                    in_array($this->shishen[$this->canggan[$this->bazi[4]][0]][$this->bazi[5]], ['七杀', '正官']))
            ) {
                $taohua += 8;
            }
        } // 本命日支
        elseif (
            // 流年地支来合
            $this->is_liuhe($y_zhi, $this->bazi[6]) &&
            // 被冲或穿
            ($this->liuchong($this->bazi[6], $temp_arr) || $this->liuhai($this->bazi[6], $temp_arr))

        ) {
            if (
                ($this->sex == 1 &&
                    in_array($this->shishen[$this->canggan[$this->bazi[6]][0]][$this->bazi[5]], ['偏财', '正财']))
                ||
                ($this->sex == 2 &&
                    in_array($this->shishen[$this->canggan[$this->bazi[6]][0]][$this->bazi[5]], ['七杀', '正官']))
            ) {
                $taohua += 8;
            }
        } // 本命时支
        elseif (
            // 流年地支来合
            $this->is_liuhe($y_zhi, $this->bazi[8]) &&
            // 被冲或穿
            ($this->liuchong($this->bazi[8], $temp_arr) || $this->liuhai($this->bazi[8], $temp_arr))

        ) {
            if (
                ($this->sex == 1 &&
                    in_array($this->shishen[$this->canggan[$this->bazi[8]][0]][$this->bazi[5]], ['偏财', '正财']))
                ||
                ($this->sex == 2 &&
                    in_array($this->shishen[$this->canggan[$this->bazi[8]][0]][$this->bazi[5]], ['七杀', '正官']))
            ) {
                $taohua += 8;
            }
        } // 大运地支
        elseif (
            // 流年地支来合
            $this->is_liuhe($y_zhi, $d_zhi) &&
            // 被冲或穿
            ($this->liuchong($d_zhi, $temp_arr) || $this->liuhai($d_zhi, $temp_arr))

        ) {
            if (
                ($this->sex == 1 &&
                    in_array($this->shishen[$dazhi][$this->bazi[5]], ['偏财', '正财']))
                ||
                ($this->sex == 2 &&
                    in_array($this->shishen[$dazhi][$this->bazi[5]], ['七杀', '正官']))
            ) {
                $taohua += 8;
            }
        }
        // 7.运财官 大运地支本气为财（男）或官杀（女），流年地支合之【+10】，流年地支拱之【+7】，流年地支冲之【+5】，
        if (
            ($this->sex == 1 && in_array($this->shishen[$dazhi][$this->bazi[5]], ['偏财', '正财']))
            || ($this->sex == 2 && in_array($this->shishen[$dazhi][$this->bazi[5]], ['七杀', '正官']))
        ) {
            if ($this->is_liuhe($y_zhi, $d_zhi)) {
                $taohua += 10;
            }
            if ($this->is_gong($y_zhi, $d_zhi)) {
                $taohua += 7;
            }
            if ($this->is_liuchong($y_zhi, $d_zhi)) {
                $taohua += 5;
            }
        }
        // 8.禄出干 流年天干是财（男）或官杀（女），且其禄为本命地支或大运地支之一，【+8】
        if (
            (($this->sex == 1 && in_array($this->shishen[$y_gan][$this->bazi[5]], ['偏财', '正财']))
                || ($this->sex == 2 && in_array($this->shishen[$y_gan][$this->bazi[5]], ['七杀', '正官'])))
            && (
                $this->is_lushen($y_gan, $this->bazi[2])
                || $this->is_lushen($y_gan, $this->bazi[4])
                || $this->is_lushen($y_gan, $this->bazi[6])
                || $this->is_lushen($y_gan, $this->bazi[8])
                || $this->is_lushen($y_gan, $d_zhi)
            )
        ) {
            $taohua += 8;
        }
        // 9.宫出干 流年天干的禄是日支【+9】；
        if ($this->is_lushen($y_gan, $this->bazi[6])) {
            $taohua += 9;
        }
        // 日支是辰戌丑未，流干是日支非土藏干之一【+7】
        if (
            in_array($this->bazi[6], ['辰', '戌', '丑', '未'])
            && in_array($y_gan, [$this->canggan[$this->bazi[6]][1], $this->canggan[$this->bazi[6]][2]])
        ) {
            $taohua += 7;
            // 此时日干是壬癸【+3】
            if ($this->bazi[5] == '壬' || $this->bazi[5] == '癸') {
                $taohua += 3;
            }
        }
        // 10.支伏吟 若流年地支是四柱或大运地支有本气财（男）或官杀（女）【+6】
        if (in_array($y_zhi, $temp_arr) &&
            (($this->sex == 1 && in_array($this->shishen[$liuzhi][$this->bazi[5]], ['偏财', '正财']))
                || ($this->sex == 2 && in_array($this->shishen[$liuzhi][$this->bazi[5]], ['七杀', '正官'])))

        ) {
            $taohua += 6;
        }
        // 11.宫伏吟 若流年地支是日支【+6】
        if ($this->bazi[6] == $y_zhi) {
            $taohua += 6;
        }
        // 12.流年地支拱到日支【+6】
        if ($this->is_gong($this->bazi[6], $y_zhi)) {
            $taohua += 6;
        }
        // 13.运比肩：流支合或冲运支，若此时运干比肩+3，运支合或拱日支+6，运支合或拱本命财星（男命，此财星是指某柱天干或地支本气）+6
        if ($this->is_liuhe($y_zhi, $d_zhi) || $this->is_liuchong($y_zhi, $d_zhi)) {
            if ($this->shishen[$d_gan][$this->bazi[5]] == '比肩') {
                $taohua += 3;
                if ($this->is_liuhe($this->bazi[6], $d_zhi) || $this->is_gong($this->bazi[6], $d_zhi)) {
                    $taohua += 6;
                }
                if (
                    (
                        ($this->is_liuhe($this->bazi[1], $d_zhi)
                            || $this->is_gong($this->bazi[1], $d_zhi))
                        && in_array($this->shishen[$this->bazi[1]][$this->bazi[5]], ['偏财', '正财'])
                    )
                    ||
                    (
                        ($this->is_liuhe($this->bazi[3], $d_zhi)
                            || $this->is_gong($this->bazi[3], $d_zhi))
                        && in_array($this->shishen[$this->bazi[3]][$this->bazi[5]], ['偏财', '正财'])
                    )
                    ||
                    (
                        ($this->is_liuhe($this->bazi[7], $d_zhi)
                            || $this->is_gong($this->bazi[7], $d_zhi))
                        && in_array($this->shishen[$this->bazi[7]][$this->bazi[5]], ['偏财', '正财'])
                    )
                    ||
                    (
                        ($this->is_liuhe($this->bazi[2], $d_zhi)
                            || $this->is_gong($this->bazi[2], $d_zhi))
                        && in_array($this->shishen[$this->canggan[$this->bazi[2]][0]][$this->bazi[5]], ['偏财', '正财'])
                    )
                    ||
                    (
                        ($this->is_liuhe($this->bazi[4], $d_zhi)
                            || $this->is_gong($this->bazi[4], $d_zhi))
                        && in_array($this->shishen[$this->canggan[$this->bazi[4]][0]][$this->bazi[5]], ['偏财', '正财'])
                    )
                    ||
                    (
                        ($this->is_liuhe($this->bazi[6], $d_zhi)
                            || $this->is_gong($this->bazi[6], $d_zhi))
                        && in_array($this->shishen[$this->canggan[$this->bazi[6]][0]][$this->bazi[5]], ['偏财', '正财'])
                    )
                    ||
                    (
                        ($this->is_liuhe($this->bazi[8], $d_zhi)
                            || $this->is_gong($this->bazi[8], $d_zhi))
                        && in_array($this->shishen[$this->canggan[$this->bazi[8]][0]][$this->bazi[5]], ['偏财', '正财'])
                    )
                ) {
                    $taohua += 6;
                }
            }
        }


        $Third = new ThirdprogressedController();
        $Third->recode = $this->userinfo;

        $th_4_1 = json_decode($Third->get($year . "-4-1", true), true)['data']['planets'];

        $th_10_1 = json_decode($Third->get($year . "-10-1", true), true)['data']['planets'];
        $score_4_1 = 0;
        $score_10_1 = 0;
        if (isset($th_4_1[0]['phase']['0-3']) && $th_4_1[0]['phase']['0-3']['phase_e'] == 0) {
            $score_4_1 += 5;
            if (isset($th_4_1[3]['phase']['3-5'])) $score_4_1 += 5;
            if (in_array($th_4_1[3]['in_house_id'], [5, 7])) $score_4_1 += 5;
        }
        if (isset($th_4_1[3]['phase']['3-4']) && $th_4_1[3]['phase']['3-4']['phase_e'] == 0) {
            $score_4_1 += 5;
            if (isset($th_4_1[3]['phase']['3-5'])) $score_4_1 += 5;
            if (in_array($th_4_1[3]['in_house_id'], [5, 7])) $score_4_1 += 5;
        }
        if (isset($th_4_1[0]['phase']['0-4']) && $th_4_1[0]['phase']['0-4']['phase_e'] == 0) {
            $score_4_1 += 2;
            if (isset($th_4_1[4]['phase']['4-5'])) $score_4_1 += 5;
            if (in_array($th_4_1[3]['in_house_id'], [5, 7]) || in_array($th_4_1[4]['in_house_id'], [5, 7])) $score_4_1 += 5;
        }
        if ($score_4_1 == 0 && isset($th_4_1[3]['phase']['3-5'])) {
            $score_4_1 += 5;
            if (in_array($th_4_1[3]['in_house_id'], [5, 7]) || in_array($th_4_1[5]['in_house_id'], [5, 7])) $score_4_1 += 5;
        }
        if (isset($th_10_1[0]['phase']['0-3']) && $th_10_1[0]['phase']['0-3']['phase_e'] == 0) {
            $score_10_1 += 5;
            if (isset($th_10_1[3]['phase']['3-5'])) $score_10_1 += 5;
            if (in_array($th_10_1[3]['in_house_id'], [5, 7])) $score_10_1 += 5;
        }
        if (isset($th_10_1[3]['phase']['3-4']) && $th_10_1[3]['phase']['3-4']['phase_e'] == 0) {
            $score_10_1 += 5;
            if (isset($th_10_1[3]['phase']['3-5'])) $score_10_1 += 5;
            if (in_array($th_10_1[3]['in_house_id'], [5, 7])) $score_10_1 += 5;
        }
        if (isset($th_10_1[0]['phase']['0-4']) && $th_10_1[0]['phase']['0-4']['phase_e'] == 0) {
            $score_10_1 += 2;
            if (isset($th_10_1[4]['phase']['4-5'])) $score_10_1 += 5;
            if (in_array($th_10_1[3]['in_house_id'], [5, 7]) || in_array($th_10_1[4]['in_house_id'], [5, 7])) $score_10_1 += 5;
        }
        if ($score_10_1 == 0 && isset($th_10_1[3]['phase']['3-5'])) {
            $score_10_1 += 5;
            if (in_array($th_10_1[3]['in_house_id'], [5, 7]) || in_array($th_10_1[5]['in_house_id'], [5, 7])) $score_10_1 += 5;
        }
        if ($score_4_1 > $score_10_1) {
            $taohua += $score_4_1;
        } else {
            $taohua += $score_10_1;
        }
        $lv = 0;
        if ($taohua >= 30) $lv = 3;
        elseif ($taohua >= 20) $lv = 2;
        elseif ($taohua > 10) $lv = 1;


//        echo "<pre>";
//        echo $y_gan;
//        echo $y_zhi.'-'.$year.'    '.$taohua.'分   ';
//
//
//        echo '【'.$lv.'】级<br/>';

//        print_r($th_4_1);
//        print_r($th_10_1);
        return $taohua;
    }

    /**
     * 检测某地支是否被穿（六害）
     * @param $zhi 地支
     * @param array $arr 地支数组
     * @return bool false 未被穿 || true 被穿
     */
    private function liuhai($zhi, $arr = [])
    {
        foreach ($arr as $a) if ($this->is_liuhai($zhi, $a)) return true;
        return false;
    }

    /**
     * 检测某地支是否被冲
     * @param $zhi 地支
     * @param array $arr 地支数组
     * @return bool false 未被冲  || true 被冲
     */
    private function liuchong($zhi, $arr = [])
    {
        foreach ($arr as $a) if ($this->is_liuchong($zhi, $a)) return true;
        return false;
    }

    /**
     * 获取起运时间
     */
    /**
     * 获取起运时间
     */
    public function dayun()
    {
        $num = array_search($this->bazi[1], $this->Heavenly_Stems);

        $birth_day_time_0 = $this->birth_time - ($this->userinfo['timezone'] * 3600 + 3600 * $this->userinfo['is_summer']);

        // 阳男 || 阴女 六十甲子顺行 下一个节令时间 （节令黄经度数 为15°的奇数倍数）
        if (($num % 2 == 0 && $this->sex == 1) || ($num % 2 == 1 && $this->sex == 2)) {
            $r = false;// 阳男 || 阴女  顺推

            $luck_time = (new SolarTerms())->getTremTime(['time' => $birth_day_time_0, 'sort' => 'asc']);

//            $time = Db::table('wechat.app_solar_terms')->field('time,deg')->where('time' ,'>',$birth_day_time_0)->order('time ASC')->limit(2)->select();
        } // 阴男 || 阳女 六十甲子逆行  上一个节令时间 （节令黄经度数 为15°的奇数倍数）
        else {
            $r = true;// 阴男 || 阳女 逆推

            $luck_time = (new SolarTerms())->getTremTime(['time' => $birth_day_time_0, 'sort' => 'desc']);
        }
//        // 阴男 || 阳女 六十甲子逆行  上一个节令时间 （节令黄经度数 为15°的奇数倍数）
//        elseif(($num % 2 == 1 && $this->sex == 1) || ($num % 2 == 0 && $this->sex == 2))
//        {
//            $r = true;// 阴男 || 阳女 逆推
//
//            $time = (new SolarTerms())->getTremTime(['time'=>$birth_day_time_0,'sort'=>'desc']);
//
////            $time = Db::table('wechat.app_solar_terms')->field('time,deg')->where('time' ,'<',$birth_day_time_0)->order('time DESC')->limit(2)->select();
//        }


        $diff_year = abs($birth_day_time_0 - $luck_time) / 3600 / 24 / 3;

        $st_time = $this->birth_time + $diff_year * 365 * 24 * 3600;

        // 大运
        $yuezhu = $this->bazi[3] . $this->bazi[4];
        $dayun_bazi_array = array_merge($this->Chinese_era, $this->Chinese_era, $this->Chinese_era);
        $index = array_search($yuezhu, $dayun_bazi_array) + 60;
        if ($r == true) {
            $index -= 6;
            $this->dayun = array_reverse(array_slice($dayun_bazi_array, $index, 6));
        } else {
            $index++;
            $this->dayun = array_slice($dayun_bazi_array, $index, 6);
        }

        $this->st_time = $st_time;
    }


    /**
     * 获取指定时间太阳所在度数
     * @param null $time
     * @param int $timezone
     * @param int $is_summer
     * @return mixed
     */
    private function getSundeg($time = null, $timezone = 8, $is_summer = 0)
    {
        $time -= ($timezone * 3600 + 3600 * $is_summer);

        $utdatenow = strftime("%d.%m.%Y", $time);
        $utnow = strftime("%H:%M:%S", $time);

        $exec_str = config('astrolog.prefix') . " -b{$utdatenow} -ut{$utnow} -p0 -eswe -fl -g, -head";

        exec($exec_str, $out);

        $sunDeg = $out[0] * 1;

        return $sunDeg;
    }

    /**
     * 获取当前生辰八字
     * @param $userinfo
     * @return string
     */
    private function getBazi($userinfo)
    {
//        dump($userinfo);
//        exit;
        $year_stem_branche = $this->getYearStemBranche($userinfo['year']);
//        dump($year_stem_branche);
//        dump($this->birth_sun_deg);
        if ($userinfo['month'] < 3 && $this->birth_sun_deg < 315) {
            $year_stem_branche--;
            if ($year_stem_branche < 0) $year_stem_branche = 59;
        }
        $month_stem_branche = $this->getMonthStemBranche($this->Chinese_era[$year_stem_branche]);
        $day_stem_branche = $this->getDayStemBranche($userinfo);
        $hour_stem_branche = $this->getHourStemBranche($this->Chinese_era[$day_stem_branche], $userinfo);
        $str = '';
        $str .= $this->Chinese_era[$year_stem_branche];
        $str .= $month_stem_branche;
        $str .= $this->Chinese_era[$day_stem_branche];
        $str .= $hour_stem_branche;
//        dump($this->Chinese_era);
        $this->bazi = [
            1 => mb_substr($str, 0, 1, 'utf8'), 2 => mb_substr($str, 1, 1, 'utf8'),
            3 => mb_substr($str, 2, 1, 'utf8'), 4 => mb_substr($str, 3, 1, 'utf8'),
            5 => mb_substr($str, 4, 1, 'utf8'), 6 => mb_substr($str, 5, 1, 'utf8'),
            7 => mb_substr($str, 6, 1, 'utf8'), 8 => mb_substr($str, 7, 1, 'utf8'),
        ];
//        dump($this->bazi);
//        exit;
    }

    /**
     * 获取五行得分
     * @return json
     */
    public function get_wuxing_by_ajax()
    {
        echo "<pre>";
        echo "八字：" . implode('', $this->bazi) . '<br/>';

        $this->getTianGanScore($this->bazi[1], $this->bazi[2]);
        $this->getTianGanScore($this->bazi[3], $this->bazi[4]);
        $this->getTianGanScore($this->bazi[5], $this->bazi[6]);
        $this->getTianGanScore($this->bazi[7], $this->bazi[8]);
//        print_r($this->score);
        $this->getDizhiScore($this->bazi[2]);
        $this->getDizhiScore($this->bazi[4], true);
        $this->getDizhiScore($this->bazi[6]);
        $this->getDizhiScore($this->bazi[8]);
//        print_r($this->score);
        $this->getShengkeScore($this->bazi[5]);

        $sum = array_sum($this->score);
        foreach ($this->score as $k => $s) {
            $perc[$k] = round($s / $sum * 100, 0) . '%';
        }
        print_r($this->score);
        print_r($perc);
//        return $perc;
    }

    /**
     * 获取五行百分比
     * @return mixed
     */
    private function get_wuxing_percent()
    {
        $this->getTianGanScore($this->bazi[1], $this->bazi[2]);
        $this->getTianGanScore($this->bazi[3], $this->bazi[4]);
        $this->getTianGanScore($this->bazi[5], $this->bazi[6]);
        $this->getTianGanScore($this->bazi[7], $this->bazi[8]);
        $this->getDizhiScore($this->bazi[2]);
        $this->getDizhiScore($this->bazi[4], true);
        $this->getDizhiScore($this->bazi[6]);
        $this->getDizhiScore($this->bazi[8]);
        $this->getShengkeScore($this->bazi[5]);

        $sum = array_sum($this->score);
        foreach ($this->score as $k => $s) {
            $perc[$k] = round($s / $sum * 100, 0);
        }
        return $perc;
    }

    /**
     * 获取十神
     * @return array
     */
    public function getShishen()
    {
        $shishen = [];
        for ($i = 1; $i < 9; $i++) {
            if ($i == 5) continue;
            $rigan = $this->bazi[5];
            $other = $this->bazi[$i];
//            $loc = ceil($i / 2);
            // 干
            if ($i % 2 == 1) {
                $shishen['gan'][$i] = [
                    'a' => $rigan,
                    'b' => $other,
                    'relation' => $this->shishen[$other][$rigan],
                    'loc' => $i,
                ];
            } // 藏干
            else {
                foreach ($this->canggan[$other] as $k => $g) {
                    $benqi = $k === 0 ? true : false;
                    $shishen['cang'][$i][] = [
                        'a' => $rigan,
                        'b' => $other,
                        'relation' => $this->shishen[$g][$rigan],
                        'loc' => $i,
                        'benqi' => $benqi
                    ];
                }
            }
        }
        return $shishen;
    }

    /**
     * 获取神煞
     * @return array
     */
    public function getShensha()
    {
        $huagai = $this->huagai();
        $taohua = $this->taohua();
        $yima = $this->yima();
        $wangshen = $this->wangshen();
        $jiesha = $this->jiesha();
        $jiangxing = $this->jiangxing();
        $zaisha = $this->zaisha();
        $tianyiguiren = $this->tianyiguiren();
        $tiandeguiren = $this->tiandeguiren();
        $wenchangguiren = $this->wenchangguiren();
        $yuedeguiren = $this->yuedeguiren();
        $jinyu = $this->jinyu();
        $hongyansha = $this->hongyansha();
        $guchen = $this->guchen();
        $guaxiu = $this->guaxiu();
        $lushen = $this->lushen();
        $yangren = $this->yangren();
        $jinshen = $this->jinshen();
        $shensha = array_merge($huagai, $taohua, $yima, $wangshen, $jiesha, $jiangxing, $zaisha, $tianyiguiren, $tiandeguiren, $wenchangguiren, $yuedeguiren, $jinyu, $hongyansha, $guchen, $guaxiu, $lushen, $yangren, $jinshen);

        return $shensha;

    }

    /**
     * 获取十神
     * @return json
     */
    public function get_shishen_by_ajax()
    {
        $ret = [];
        for ($i = 1; $i < 9; $i++) {
            if ($i == 5) continue;
            $rigan = $this->bazi[5];
            $other = $this->bazi[$i];
//            $loc = ceil($i / 2);
            // 干
            if ($i % 2 == 1) {
                $ret['gan'][$i] = [
                    'a' => $rigan,
                    'b' => $other,
                    'relation' => $this->shishen[$other][$rigan],
                    'loc' => $i,
                ];
            } // 藏干
            else {
                foreach ($this->canggan[$other] as $k => $g) {
                    $benqi = $k === 0 ? true : false;
                    $ret['cang'][$i][] = [
                        'a' => $rigan,
                        'b' => $other,
                        'relation' => $this->shishen[$g][$rigan],
                        'loc' => $i,
                        'benqi' => $benqi
                    ];
                }
            }
        }
        return json(['code' => 200, 'data' => $ret, 'msg' => 'Success.']);
    }

    /**
     * 获取神煞
     * @return json
     */
    public function get_shensha_by_ajax()
    {
        $huagai = $this->huagai();
        $taohua = $this->taohua();
        $yima = $this->yima();
        $wangshen = $this->wangshen();
        $jiesha = $this->jiesha();
        $jiangxing = $this->jiangxing();
        $zaisha = $this->zaisha();
        $tianyiguiren = $this->tianyiguiren();
        $tiandeguiren = $this->tiandeguiren();
        $wenchangguiren = $this->wenchangguiren();
        $yuedeguiren = $this->yuedeguiren();
        $jinyu = $this->jinyu();
        $hongyansha = $this->hongyansha();
        $guchen = $this->guchen();
        $guaxiu = $this->guaxiu();
        $lushen = $this->lushen();
        $yangren = $this->yangren();
        $jinshen = $this->jinshen();
        $shensha = array_merge($huagai, $taohua, $yima, $wangshen, $jiesha, $jiangxing, $zaisha, $tianyiguiren, $tiandeguiren, $wenchangguiren, $yuedeguiren, $jinyu, $hongyansha, $guchen, $guaxiu, $lushen, $yangren, $jinshen);

        return json(['code' => 200, 'data' => $shensha, 'msg' => 'Success.']);

    }

    /**
     * 获取天干五行得分
     */
    private function getTianGanScore($gan = null, $zhi = null)
    {
        $base = 6;
        $wuxing = $this->wuxing[$gan];
        $status = false;
        $change = 0;
        foreach ($this->canggan[$zhi] as $k1 => $cg1) {
            // 本气40
            if ($k1 === 0) {
                // 坐支本气为相同五行成分
                if ($wuxing == $this->wuxing[$cg1]) {
                    $status = true;
                    $change += 5;
                }
                // 坐支本气正印
                if ($this->shishen[$cg1][$gan] == '正印') {
                    $status = true;
                    $change += 3;
                } // 坐支本气偏印
                elseif ($this->shishen[$cg1][$gan] == '偏印') {
                    $status = true;
                    $change += 1;
                } // 坐支本气七杀
                elseif ($this->shishen[$cg1][$gan] == '七杀') {
                    $status = true;
                    $change += -4;
                } // 坐支本气正官
                elseif ($this->shishen[$cg1][$gan] == '正官') {
                    $status = true;
                    $change += -2;
                } // 坐支本气正财
                elseif ($this->shishen[$cg1][$gan] == '正财') {
                    $status = true;
                    $change += -1;
                } // 坐支本气偏财
                elseif ($this->shishen[$cg1][$gan] == '偏财') {
                    $status = true;
                    $change += -1;
                }
            } else {
                // 坐支非本气为相同五行成分
                if ($wuxing == $this->wuxing[$cg1]) {
                    $status = true;
                    $change += 3;
                }
            }
        }
        if ($status == true) $change += $base;

        $this->score[$wuxing] += $change;
    }

    /**
     * 获取地支五行得分
     * @param null $zhi
     * @param bool $is_m 是否为月令
     */
    private function getDizhiScore($zhi = null, $is_m = false)
    {
        $metal = $wood = $water = $fire = $earth = 0;
        switch ($zhi) {
            case '子':
                $water += 10;
                break;
            case '丑':
                $earth += 6;
                $water += 2;
                $metal += 2;
                break;
            case '寅':
                $wood += 7;
                $fire += 2.5;
                $earth += 0.5;
                break;
            case '卯':
                $wood += 10;
                break;
            case '辰':
                $earth += 6;
                $wood += 2;
                $water += 2;
                break;
            case '巳':
                $fire += 7;
                $earth += 2.5;
                $metal += 0.5;
                break;
            case '午':
                $fire += 8;
                $earth += 4;
                break;
            case '未':
                $earth += 6;
                $wood += 2;
                $fire += 2;
                break;
            case '申':
                $metal += 7;
                $water += 2.5;
                $earth += 0.5;
                break;
            case '酉':
                $metal += 10;
                break;
            case '戌':
                $earth += 6;
                $fire += 2;
                $metal += 2;
                break;
            case '亥':
                $water += 7;
                $wood += 3;
                break;
        }

        if ($is_m) {
            $metal *= 2;
            $wood *= 2;
            $water *= 2;
            $fire *= 2;
            $earth *= 2;
        }
        $this->score['金'] += $metal;
        $this->score['木'] += $wood;
        $this->score['水'] += $water;
        $this->score['火'] += $fire;
        $this->score['土'] += $earth;
    }

    /**
     * 五行生克得分
     * @param null $rizhu
     */
    private function getShengkeScore($rizhu = null)
    {
        $wuxing = $this->wuxing[$rizhu];
        switch ($wuxing) {
            case '金':
                $this->score['金'] *= 1;// 同我
                $this->score['土'] *= 0.5;// 生我
                $this->score['火'] *= 1;// 克我
                $this->score['木'] *= 0.6;// 我克
                $this->score['水'] *= 0.3;// 我生
                break;
            case '水':
                $this->score['水'] *= 1;
                $this->score['金'] *= 0.5;
                $this->score['土'] *= 1;
                $this->score['火'] *= 0.6;
                $this->score['木'] *= 0.3;
                break;
            case '木':
                $this->score['木'] *= 1;
                $this->score['水'] *= 0.5;
                $this->score['金'] *= 1;
                $this->score['土'] *= 0.6;
                $this->score['火'] *= 0.3;
                break;
            case '火':
                $this->score['火'] *= 1;
                $this->score['木'] *= 0.5;
                $this->score['水'] *= 1;
                $this->score['金'] *= 0.6;
                $this->score['土'] *= 0.3;
                break;
            case '土':
                $this->score['土'] *= 1;
                $this->score['火'] *= 0.5;
                $this->score['木'] *= 1;
                $this->score['水'] *= 0.6;
                $this->score['金'] *= 0.3;
                break;
        }
    }

    /**
     * 华盖
     * @return array
     */
    private function huagai()
    {
        $ret = [];
        $name = '华盖';
        if ($this->is_huagai($this->bazi[6], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_huagai($this->bazi[6], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 6,
            ];
        }
        if ($this->is_huagai($this->bazi[6], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        if ($this->is_huagai($this->bazi[2], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_huagai($this->bazi[2], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_huagai($this->bazi[2], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 桃花
     * @return array
     */
    private function taohua()
    {
        $ret = [];
        $name = '桃花';
        if ($this->is_taohua($this->bazi[6], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_taohua($this->bazi[6], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 6,
            ];
        }
        if ($this->is_taohua($this->bazi[6], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        if ($this->is_taohua($this->bazi[2], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_taohua($this->bazi[2], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_taohua($this->bazi[2], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 驿马
     * @return array
     */
    private function yima()
    {
        $ret = [];
        $name = '驿马';
        if ($this->is_yima($this->bazi[6], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_yima($this->bazi[6], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 6,
            ];
        }
        if ($this->is_yima($this->bazi[6], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        if ($this->is_yima($this->bazi[2], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_yima($this->bazi[2], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_yima($this->bazi[2], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 亡神
     * @return array
     */
    private function wangshen()
    {
        $ret = [];
        $name = '亡神';
        if ($this->is_wangshen($this->bazi[6], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_wangshen($this->bazi[6], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 6,
            ];
        }
        if ($this->is_wangshen($this->bazi[6], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        if ($this->is_wangshen($this->bazi[2], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_wangshen($this->bazi[2], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_wangshen($this->bazi[2], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 劫煞
     * @return array
     */
    private function jiesha()
    {
        $ret = [];
        $name = '劫煞';
        if ($this->is_jiesha($this->bazi[6], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_jiesha($this->bazi[6], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 6,
            ];
        }
        if ($this->is_jiesha($this->bazi[6], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        if ($this->is_jiesha($this->bazi[2], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_jiesha($this->bazi[2], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_jiesha($this->bazi[2], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 将星
     * @return array
     */
    private function jiangxing()
    {
        $ret = [];
        $name = '将星';
        if ($this->is_jiangxing($this->bazi[6], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_jiangxing($this->bazi[6], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 6,
            ];
        }
        if ($this->is_jiangxing($this->bazi[6], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        if ($this->is_jiangxing($this->bazi[2], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_jiangxing($this->bazi[2], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_jiangxing($this->bazi[2], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 灾煞
     * @return array
     */
    private function zaisha()
    {
        $ret = [];
        $name = '灾煞';
        if ($this->is_zaisha($this->bazi[6], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_zaisha($this->bazi[6], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 6,
            ];
        }
        if ($this->is_zaisha($this->bazi[6], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[6], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        if ($this->is_zaisha($this->bazi[2], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_zaisha($this->bazi[2], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_zaisha($this->bazi[2], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2], $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 天乙贵人
     * @return array
     */
    private function tianyiguiren()
    {
        $ret = [];
        $name = '天乙贵人';
        if ($this->is_tianyiguiren($this->bazi[1], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[1] . $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_tianyiguiren($this->bazi[1], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[1] . $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        if ($this->is_tianyiguiren($this->bazi[5], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[2],
                'location_cn' => '月支',
                'location_num' => 2,
            ];
        }
        if ($this->is_tianyiguiren($this->bazi[5], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_tianyiguiren($this->bazi[5], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_tianyiguiren($this->bazi[5], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 天德贵人
     * @return array
     */
    private function tiandeguiren()
    {
        $ret = [];
        $name = '天德贵人';
        if ($this->is_tiandeguiren($this->bazi[4], $this->bazi[5])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[4] . $this->bazi[5],
                'location_cn' => '日干',
                'location_num' => 5,
            ];
        }
        if ($this->is_tiandeguiren($this->bazi[4], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[4] . $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_tiandeguiren($this->bazi[4], $this->bazi[7])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[4] . $this->bazi[7],
                'location_cn' => '时干',
                'location_num' => 7,
            ];
        }
        if ($this->is_tiandeguiren($this->bazi[4], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[4] . $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 文昌贵人
     * @return array
     */
    private function wenchangguiren()
    {
        $ret = [];
        $name = '文昌贵人';
        if ($this->is_wenchangguiren($this->bazi[5], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_wenchangguiren($this->bazi[5], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_wenchangguiren($this->bazi[5], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_wenchangguiren($this->bazi[5], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 月德贵人
     * @return array
     */
    private function yuedeguiren()
    {
        $ret = [];
        $name = '月德贵人';
        if ($this->is_yuedeguiren($this->bazi[4], $this->bazi[5])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[4] . $this->bazi[5],
                'location_cn' => '日干',
                'location_num' => 5,
            ];
        }
        if ($this->is_yuedeguiren($this->bazi[4], $this->bazi[7])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[4] . $this->bazi[7],
                'location_cn' => '时干',
                'location_num' => 7,
            ];
        }
        return $ret;
    }

    /**
     * 金舆
     * @return array
     */
    private function jinyu()
    {
        $ret = [];
        $name = '金舆';
        if ($this->is_jinyu($this->bazi[5], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_jinyu($this->bazi[5], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_jinyu($this->bazi[5], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_jinyu($this->bazi[5], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 红艳煞
     * @return array
     */
    private function hongyansha()
    {
        $ret = [];
        $name = '红艳煞';
        if ($this->is_hongyansha($this->bazi[5], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_hongyansha($this->bazi[5], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_hongyansha($this->bazi[5], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_hongyansha($this->bazi[5], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 孤辰
     * @return array
     */
    private function guchen()
    {
        $ret = [];
        $name = '孤辰';
        if ($this->is_guchen($this->bazi[2], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2] . $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_guchen($this->bazi[2], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2] . $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 寡宿
     * @return array
     */
    private function guaxiu()
    {
        $ret = [];
        $name = '寡宿';
        if ($this->is_guaxiu($this->bazi[2], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2] . $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_guaxiu($this->bazi[2], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[2] . $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 禄神
     * @return array
     */
    private function lushen()
    {
        $ret = [];
        $name = '禄神';
        if ($this->is_lushen($this->bazi[5], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_lushen($this->bazi[5], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_lushen($this->bazi[5], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_lushen($this->bazi[5], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 羊刃
     * @return array
     */
    private function yangren()
    {
        $ret = [];
        $name = '羊刃';
        if ($this->is_yangren($this->bazi[5], $this->bazi[2])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[2],
                'location_cn' => '年支',
                'location_num' => 2,
            ];
        }
        if ($this->is_yangren($this->bazi[5], $this->bazi[4])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[4],
                'location_cn' => '月支',
                'location_num' => 4,
            ];
        }
        if ($this->is_yangren($this->bazi[5], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_yangren($this->bazi[5], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 金神
     * @return array
     */
    private function jinshen()
    {
        $ret = [];
        $name = '金神';
        if ($this->is_jinshen($this->bazi[5], $this->bazi[6])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[5] . $this->bazi[6],
                'location_cn' => '日支',
                'location_num' => 6,
            ];
        }
        if ($this->is_jinshen($this->bazi[7], $this->bazi[8])) {
            $ret[] = [
                'name' => $name,
                'condition' => $this->bazi[7] . $this->bazi[8],
                'location_cn' => '时支',
                'location_num' => 8,
            ];
        }
        return $ret;
    }

    /**
     * 检查是否为华盖
     * @param null $zhi1 日支/年支
     * @param null $zhi2 其他三个地支
     * @return bool
     */
    private function is_huagai($zhi1 = null, $zhi2 = null)
    {
        $rizhi_nianzhi = [
            ['寅', '午', '戌'],
            ['亥', '卯', '未'],
            ['申', '子', '辰'],
            ['巳', '酉', '丑'],
        ];
        $jian = ['戌', '未', '辰', '丑'];
        foreach ($rizhi_nianzhi as $k => $rn) if (in_array($zhi1, $rn) && $zhi2 == $jian[$k]) return true;
        return false;
    }

    /**
     * 检查是否为桃花
     * @param null $zhi1 日支/年支
     * @param null $zhi2 其他三个地支
     * @return bool
     */
    private function is_taohua($zhi1 = null, $zhi2 = null)
    {
        $rizhi_nianzhi = [
            ['寅', '午', '戌'],
            ['亥', '卯', '未'],
            ['申', '子', '辰'],
            ['巳', '酉', '丑'],
        ];
        $jian = ['卯', '子', '酉', '午'];
        foreach ($rizhi_nianzhi as $k => $rn) if (in_array($zhi1, $rn) && $zhi2 == $jian[$k]) return true;
        return false;
    }

    /**
     * 检查是否为驿马
     * @param null $zhi1 日支/年支
     * @param null $zhi2 其他三个地支
     * @return bool
     */
    private function is_yima($zhi1 = null, $zhi2 = null)
    {
        $rizhi_nianzhi = [
            ['寅', '午', '戌'],
            ['亥', '卯', '未'],
            ['申', '子', '辰'],
            ['巳', '酉', '丑'],
        ];
        $jian = ['申', '巳', '寅', '亥'];
        foreach ($rizhi_nianzhi as $k => $rn) if (in_array($zhi1, $rn) && $zhi2 == $jian[$k]) return true;
        return false;
    }

    /**
     * 检查是否为亡神
     * @param null $zhi1 日支/年支
     * @param null $zhi2 其他三个地支
     * @return bool
     */
    private function is_wangshen($zhi1 = null, $zhi2 = null)
    {
        $rizhi_nianzhi = [
            ['寅', '午', '戌'],
            ['亥', '卯', '未'],
            ['申', '子', '辰'],
            ['巳', '酉', '丑'],
        ];
        $jian = ['巳', '寅', '亥', '申'];
        foreach ($rizhi_nianzhi as $k => $rn) if (in_array($zhi1, $rn) && $zhi2 == $jian[$k]) return true;
        return false;
    }

    /**
     * 检查是否为劫煞
     * @param null $zhi1 日支/年支
     * @param null $zhi2 其他三个地支
     * @return bool
     */
    private function is_jiesha($zhi1 = null, $zhi2 = null)
    {
        $rizhi_nianzhi = [
            ['寅', '午', '戌'],
            ['亥', '卯', '未'],
            ['申', '子', '辰'],
            ['巳', '酉', '丑'],
        ];
        $jian = ['亥', '申', '巳', '寅'];
        foreach ($rizhi_nianzhi as $k => $rn) if (in_array($zhi1, $rn) && $zhi2 == $jian[$k]) return true;
        return false;
    }

    /**
     * 检查是否为将星
     * @param null $zhi1 日支/年支
     * @param null $zhi2 其他三个地支
     * @return bool
     */
    private function is_jiangxing($zhi1 = null, $zhi2 = null)
    {
        $rizhi_nianzhi = [
            ['寅', '午', '戌'],
            ['亥', '卯', '未'],
            ['申', '子', '辰'],
            ['巳', '酉', '丑'],
        ];
        $jian = ['午', '卯', '子', '酉'];
        foreach ($rizhi_nianzhi as $k => $rn) if (in_array($zhi1, $rn) && $zhi2 == $jian[$k]) return true;
        return false;
    }

    /**
     * 检查是否为灾煞
     * @param null $zhi1 日支/年支
     * @param null $zhi2 其他三个地支
     * @return bool
     */
    private function is_zaisha($zhi1 = null, $zhi2 = null)
    {
        $rizhi_nianzhi = [
            ['寅', '午', '戌'],
            ['亥', '卯', '未'],
            ['申', '子', '辰'],
            ['巳', '酉', '丑'],
        ];
        $jian = ['子', '酉', '午', '卯'];
        foreach ($rizhi_nianzhi as $k => $rn) if (in_array($zhi1, $rn) && $zhi2 == $jian[$k]) return true;
        return false;
    }

    /**
     * 检查是否为天乙贵人
     * @param null $gan 年干   /   日干
     * @param null $zhi 日时支  /  四地支
     * @return bool
     */
    private function is_tianyiguiren($gan = null, $zhi = null)
    {
        $lx = $this->shensha['天乙贵人'];
        if (isset($lx[$gan]) && in_array($zhi, $lx[$gan])) return true;
        else return false;
    }

    /**
     * 检查是否为天德贵人
     * @param null $ygan 月支
     * @param null $zhi 日时干支
     * @return bool
     */
    private function is_tiandeguiren($mzhi = null, $zhi = null)
    {
        $lx = $this->shensha['天德贵人'];
        if (isset($lx[$mzhi]) && $lx[$mzhi] == $zhi) return true;
        else return false;
    }

    /**
     * 检查是否为文昌贵人
     * @param null $gan 日干
     * @param null $zhi 地支
     * @return bool
     */
    private function is_wenchangguiren($gan = null, $zhi = null)
    {
        $lx = $this->shensha['文昌贵人'];
        if (isset($lx[$gan]) && $lx[$gan] == $zhi) return true;
        else return false;
    }

    /**
     * 检查是否为月德贵人
     * @param null $yzhi 月支
     * @param null $zhi 日时干支  壬丙庚甲
     * @return bool
     */
    private function is_yuedeguiren($yzhi = null, $zhi = null)
    {
        $lx = $this->shensha['月德贵人'];
        if (isset($lx[$yzhi]) && $lx[$yzhi] == $zhi) return true;
        else return false;
    }

    /**
     * 检查是否为金舆
     * @param null $gan
     * @param null $zhi
     * @return bool
     */
    private function is_jinyu($gan = null, $zhi = null)
    {
        $lx = $this->shensha['金舆'];
        if (isset($lx[$gan]) && $lx[$gan] == $zhi) return true;
        else return false;
    }

    /**
     * 检查是否为红艳煞
     * @param null $gan
     * @param null $zhi
     * @return bool
     */
    private function is_hongyansha($gan = null, $zhi = null)
    {
        $lx = $this->shensha['红艳煞'];
        if (isset($lx[$gan]) && $lx[$gan] == $zhi) return true;
        else return false;
    }

    /**
     * 检查是否为孤辰
     * @param null $gan
     * @param null $zhi
     * @return bool
     */
    private function is_guchen($gan = null, $zhi = null)
    {
        $lx = $this->shensha['孤辰'];
        if (isset($lx[$gan]) && $lx[$gan] == $zhi) return true;
        else return false;
    }

    /**
     * 检查是否为寡宿
     * @param null $gan
     * @param null $zhi
     * @return bool
     */
    private function is_guaxiu($gan = null, $zhi = null)
    {
        $lx = $this->shensha['寡宿'];
        if (isset($lx[$gan]) && $lx[$gan] == $zhi) return true;
        else return false;
    }

    /**
     * 检查是否为禄神
     * @param null $gan
     * @param null $zhi
     * @return bool
     */
    private function is_lushen($gan = null, $zhi = null)
    {
        $lx = $this->shensha['禄神'];
        if (isset($lx[$gan]) && $lx[$gan] == $zhi) return true;
        else return false;
    }

    /**
     * 检查是否为羊刃
     * @param null $gan
     * @param null $zhi
     * @return bool
     */
    private function is_yangren($gan = null, $zhi = null)
    {
        $lx = $this->shensha['羊刃'];
        if (isset($lx[$gan]) && $lx[$gan] == $zhi) return true;
        else return false;
    }

    /**
     * 检查是否为金神
     * $gan $zhi 为日干支  ||  时干支   组合
     * @param null $gan
     * @param null $zhi
     * @return bool
     */
    private function is_jinshen($gan = null, $zhi = null)
    {
        $ganzhi = $gan . $zhi;
        $lx = $this->shensha['金神'];
        foreach ($lx as $x) if ($x == $ganzhi) return true;
        return false;
    }

    /**
     * 天干五合
     * 甲己相合为土，乙庚相合为金，丙辛相合为水，丁壬相合为木，戊癸相合为火。
     * @param null $gan1
     * @param null $gan2
     * @return bool
     */
    private function is_wuhe($gan1 = null, $gan2 = null)
    {
        if (($gan1 == '甲' && $gan2 == '己') || ($gan1 == '己' && $gan2 == '甲')) {
            return true;
        } elseif (($gan1 == '乙' && $gan2 == '庚') || ($gan1 == '庚' && $gan2 == '乙')) {
            return true;
        } elseif (($gan1 == '丙' && $gan2 == '辛') || ($gan1 == '辛' && $gan2 == '丙')) {
            return true;
        } elseif (($gan1 == '丁' && $gan2 == '壬') || ($gan1 == '壬' && $gan2 == '丁')) {
            return true;
        } elseif (($gan1 == '戊' && $gan2 == '癸') || ($gan1 == '癸' && $gan2 == '戊')) {
            return true;
        }
        return false;
    }

    /**
     * 检查地支是否六合
     * @param null $zhi1
     * @param null $zhi2
     * @return bool
     */
    private function is_liuhe($zhi1 = null, $zhi2 = null)
    {
        if (!$zhi1 || !$zhi2 || $zhi1 == $zhi2) return false;
        $liuhe = ['子丑', '寅亥', '卯戌', '辰酉', '巳申', '午未'];
        foreach ($liuhe as $lh) {
            if ($zhi1 . $zhi2 == $lh || $zhi2 . $zhi1 == $lh) {
                return true;
            }
        }
        return false;
    }

    /**
     * 检查地支是否六冲
     * @param null $zhi1
     * @param null $zhi2
     * @return bool
     */
    private function is_liuchong($zhi1 = null, $zhi2 = null)
    {
        if (!$zhi1 || !$zhi2 || $zhi1 == $zhi2) return false;
        $liuchong = ['子午', '丑未', '寅申', '卯酉', '辰戌', '巳亥'];
        foreach ($liuchong as $lc) {
            if ($zhi1 . $zhi2 == $lc || $zhi2 . $zhi1 == $lc) {
                return true;
            }
        }
        return false;
    }

    /**
     * 检查地支是否六害
     * @param null $zhi1
     * @param null $zhi2
     * @return bool
     */
    private function is_liuhai($zhi1 = null, $zhi2 = null)
    {
        if (!$zhi1 || !$zhi2 || $zhi1 == $zhi2) return false;
        $liuhai = ['子未', '丑午', '寅巳', '卯辰', '申亥', '酉戌'];
        foreach ($liuhai as $lh) {
            if ($zhi1 . $zhi2 == $lh || $zhi2 . $zhi1 == $lh) {
                return true;
            }
        }
        return false;
    }

    /**
     * 检查地支是否拱
     * @param null $zhi1
     * @param null $zhi2
     * @return bool
     */
    private function is_gong($zhi1 = null, $zhi2 = null)
    {
        if (!$zhi1 || !$zhi2 || $zhi1 == $zhi2) return false;
        $gong = [['申', '子', '辰'], ['寅', '午', '戌'], ['亥', '卯', '未'], ['巳', '酉', '丑']];// 水 火 木 金
        foreach ($gong as $g) {
            if (in_array($zhi1, $g) && in_array($zhi2, $g)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 检查地支是否三合
     * @param null $zhi1
     * @param null $zhi2
     * @param null $zhi3
     * @return bool
     */
    private function is_sanhe($zhi1 = null, $zhi2 = null, $zhi3 = null)
    {
        if (!$zhi1 || !$zhi2 || !$zhi3 || $zhi1 == $zhi2 || $zhi1 == $zhi3 || $zhi2 == $zhi3) return false;
        $sanhe = ['申子辰', '寅午戌', '亥卯未', '巳酉丑'];// 水 火 木 金
        foreach ($sanhe as $sh) {
            if (
                $zhi1 . $zhi2 . $zhi3 == $sh
                || $zhi1 . $zhi3 . $zhi2 == $sh
                || $zhi2 . $zhi1 . $zhi3 == $sh
                || $zhi2 . $zhi3 . $zhi1 == $sh
                || $zhi3 . $zhi1 . $zhi2 == $sh
                || $zhi3 . $zhi2 . $zhi1 == $sh
            ) {
                return true;
            }
        }
        return false;
    }

    /**
     * 检查地支是否三会
     * @param null $zhi1
     * @param null $zhi2
     * @param null $zhi3
     * @return bool
     */
    private function is_sanhui($zhi1 = null, $zhi2 = null, $zhi3 = null)
    {
        if (!$zhi1 || !$zhi2 || !$zhi3 || $zhi1 == $zhi2 || $zhi1 == $zhi3 || $zhi2 == $zhi3) return false;
        $sanhui = ['亥子丑', '寅卯辰', '巳午未', '申酉戌'];// 水 木 火 金
        foreach ($sanhui as $sh) {
            if (
                $zhi1 . $zhi2 . $zhi3 == $sh
                || $zhi1 . $zhi3 . $zhi2 == $sh
                || $zhi2 . $zhi1 . $zhi3 == $sh
                || $zhi2 . $zhi3 . $zhi1 == $sh
                || $zhi3 . $zhi1 . $zhi2 == $sh
                || $zhi3 . $zhi2 . $zhi1 == $sh
            ) {
                return true;
            }
        }
        return false;
    }

    /**
     * 检查地支是否三刑
     * @param null $zhi1
     * @param null $zhi2
     * @param null $zhi3
     * @return bool
     */
    private function is_sanxing($zhi1 = null, $zhi2 = null, $zhi3 = null)
    {
        if (!$zhi1 || !$zhi2 || $zhi1 == $zhi2 || $zhi1 == $zhi3 || $zhi2 == $zhi3) return false;
        $sanxing = ['寅巳申', '丑戌未', '子卯'];// 水 木 火 金
        foreach ($sanxing as $sx) {
            if (
                $zhi1 . $zhi2 . $zhi3 == $sx
                || $zhi1 . $zhi3 . $zhi2 == $sx
                || $zhi2 . $zhi1 . $zhi3 == $sx
                || $zhi2 . $zhi3 . $zhi1 == $sx
                || $zhi3 . $zhi1 . $zhi2 == $sx
                || $zhi3 . $zhi2 . $zhi1 == $sx
            ) {
                return true;
            }
        }
        return false;
    }

    /**
     * 检查地支是否刑
     * 丑未为六冲  寅申为六冲  巳申为六合 排除这三种
     * @param null $zhi1
     * @param null $zhi2
     * @return bool
     */
    private function is_xing($zhi1 = null, $zhi2 = null)
    {
        if (!$zhi1 || !$zhi2 || $zhi1 == $zhi2 || (in_array($zhi1, ['丑', '未']) && in_array($zhi2, ['丑', '未']))) return false;
        $xing = [['寅', '巳'], ['丑', '戌', '未']];
        foreach ($xing as $x) {
            if (in_array($zhi1, $x) && in_array($zhi2, $x)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 检查地支是否自刑
     * @param null $zhi1
     * @param null $zhi2
     * @return bool
     */
    private function is_zixing($zhi1 = null, $zhi2 = null)
    {
        if (!$zhi1 || !$zhi2 || $zhi1 != $zhi2) return false;
        $zixing = ['辰', '午', '酉', '亥'];
        foreach ($zixing as $zx) {
            if ($zhi1 == $zx) {
                return true;
            }
        }
        return false;
    }

    /**
     * 获取年干支
     * @param null $year
     * @return int
     */
    public function getYearStemBranche($year = null)
    {
        return ($year - 4) % 60 < 0 ? ($year - 4) % 60 + 60 : ($year - 4) % 60;
    }

    /**
     * 获取月干支
     * @param null $year_stem_branche
     * @return string
     */
    public function getMonthStemBranche($year_stem_branche = null)
    {
        // 每15度一个节气   总共二十四节气  月令地支
        $month_branche = ["卯", "辰", "辰", "巳", "巳", "午", "午", "未", "未", "申", "申", "酉", "酉", "戌", "戌", "亥", "亥", "子", "子", "丑", "丑", "寅", "寅", "卯"];

        $temp = ["寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥", "子", "丑"];// 十二个月

//        $temp2 = ["丙","戊","庚","壬","甲","丙","戊","庚","壬","甲"];
        $temp2 = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0];

        $month_branche_num = intval(floor($this->birth_sun_deg / 15));// 向下取整

        $month_branche_str = $month_branche[$month_branche_num];// 月令地支

        $year_stem_branche = mb_substr($year_stem_branche, 0, 1, 'utf-8');

        $year_num = array_search($year_stem_branche, $this->Heavenly_Stems);

        $start_num = $temp2[$year_num];

        $month_branche_num = array_search($month_branche_str, $temp);

        $newArr = array_merge($this->Heavenly_Stems, $this->Heavenly_Stems, $this->Heavenly_Stems);

        $s = [];
        for ($i = $start_num; $i < $start_num + 12; $i++) {
            $s[] = $newArr[$i];
        }

        return $s[$month_branche_num] . $month_branche_str;
    }

    /**
     * 获取日干支
     * @param array $userinfo
     * @param int $time2 strtotime('1999-11-8')
     * @return int
     */
    public function getDayStemBranche($userinfo = [], $time2 = 941990400)
    {
        $time1 = strtotime("{$userinfo['year']}-{$userinfo['month']}-{$userinfo['day']}");
        $val = ($time1 - $time2) / 3600 / 24 % 60;
//        dump($userinfo);
//        dump($this->time_start);
//        dump($val);
        if ($this->time_start == 23 && $userinfo['hour'] >= 23) {

            $val++;
            if ($val == 60) $val = 0;
//            if($val >= 0)
//            {
//                $val++;
//                if($val == 60) $val = 0;
//            }
//            else
//            {
//                $val--;
//                if($val < 0) $val = 59;
//            }
        }

        $val = $val < 0 ? $val + 60 : $val;
        return $val;
    }

    /**
     * 获取时辰干支
     * @param null $year_stem_branche
     * @return string
     */
    public function getHourStemBranche($day_stem_branche = null, $userinfo = [])
    {
        // 二十四小时，十二个时辰  时辰地支
        $hour_branche = ["子", "丑", "丑", "寅", "寅", "卯", "卯", "辰", "辰", "巳", "巳", "午", "午", "未", "未", "申", "申", "酉", "酉", "戌", "戌", "亥", "亥", "子"];

//        $temp2 = ["甲","丙","戊","庚","壬","甲","丙","戊","庚","壬"];
        $temp2 = [0, 2, 4, 6, 8, 0, 2, 4, 6, 8];

        $hour_branche_str = $hour_branche[$userinfo['hour']];// 时辰地支


        $day_stem_branche = mb_substr($day_stem_branche, 0, 1, 'utf-8');

        $day_num = array_search($day_stem_branche, $this->Heavenly_Stems);

        $start_num = $temp2[$day_num];

        $hour_branche_num = array_search($hour_branche_str, $this->Earthly_Branches);

        $newArr = array_merge($this->Heavenly_Stems, $this->Heavenly_Stems, $this->Heavenly_Stems);

        $s = [];
        for ($i = $start_num; $i < $start_num + 12; $i++) {
            $s[] = $newArr[$i];
        }

        return $s[$hour_branche_num] . $hour_branche_str;
    }

    // 获取60甲子循环
    public function getChineseEra()
    {
        $Chinese_era = [];
        $k = 0;
        $n = 0;
        for ($i = 0; $i < 6; $i++) {
            for ($j = 0; $j < 10; $j++) {
                if ($k == 12) $k = 0;

                $Chinese_era[$n] = $this->Heavenly_Stems[$j] . $this->Earthly_Branches[$k];
                $n++;
                $k++;
            }
        }
        return $Chinese_era;
    }

    /**
     * 判断两天干 十神关系
     * @param null $gan1 天干1
     * @param null $gan2 天干2 一般为日干
     * @param null $rela 关系  印 官杀 财 比劫 食伤
     * @return bool
     */
    private function is_ygs($gan1 = null, $gan2 = null, $rela = null)
    {
        if (!$gan1 || !$gan2 || !$rela) return false;

        $temp = $this->shishen[$gan1][$gan2];

        if ($rela == '印' && ($temp == '正印' || $temp == '偏印')) {
            return true;
        } elseif ($rela == '官杀' && ($temp == '七杀' || $temp == '正官')) {
            return true;
        } elseif ($rela == '财' && ($temp == '正财' || $temp == '偏财')) {
            return true;
        } elseif ($rela == '比劫' && ($temp == '比肩' || $temp == '劫财')) {
            return true;
        } elseif ($rela == '食伤' && ($temp == '食神' || $temp == '伤官')) {
            return true;
        }
        return false;
    }

    /**
     * 八字格局
     * @return array
     */
    private function structure($bazi = [])
    {
        $ret = [];
        if (empty($bazi)) $bazi = $this->bazi;
        $gan_arr = [1, 3, 5, 7];
//        $y_wx = $this->wuxing[$bazi[1]];// 年干
//        $m_wx = $this->wuxing[$bazi[3]];// 月干
//        $d_wx = $this->wuxing[$bazi[5]];// 日干
//        $h_wx = $this->wuxing[$bazi[7]];// 时干
        $cg_wx__same_num = 0;
        $benqi = false;
        $tongzhu = false;
        foreach ($gan_arr as $kg => $gan) {
            $g_wx = $this->wuxing[$bazi[$gan]];// 天干
            $zhi_arr = [2, 4, 6, 8];
            foreach ($zhi_arr as $kz => $zhi) {
                $c_gan = $this->canggan[$bazi[$zhi]];// 地支藏干
                foreach ($c_gan as $kc => $cg) {
                    // 地支藏干是否有当前天干五行属性
                    if ($this->wuxing[$cg] == $g_wx) {
                        if ($kc == 0) $benqi = true;// 本气为第一个藏干 即下标为0的
                        if ($zhi - $gan == 1) $tongzhu = true;// 地支比天干大1 则为同柱
                        $cg_wx__same_num++;
                    }
                }
            }
        }
        if ($cg_wx__same_num == 0) {
            $ret[] = '虚浮';
        } elseif ($cg_wx__same_num == 1 && !$benqi && !$tongzhu) {
            $ret[] = '虚弱';
        }


        return $ret;
    }

    private function getBaseInfo($bazi = null)
    {
        if (empty($bazi)) $bazi = $this->bazi;
        $rizhu = $bazi[5];
        $ret = [];
        foreach ($bazi as $k1 => $bz1) {
            // 天干
            if ($k1 % 2 == 1) {
                $g_wx = $this->wuxing[$bz1];
                $ret[$k1] = [
                    'name' => $bz1,// 字
                    'wuxing' => $g_wx,// 五行属性
                    'shishen' => $this->shishen[$bz1][$rizhu],// 十神属性

                ];
                $zhi_wuxing_num = 0;
                $tongzhu_wuxing = false;
                // 天干五合
                foreach ($bazi as $k2 => $bz2) {
                    if ($k2 == $k1) continue;
                    if ($k2 % 2 == 0) {
//                        foreach ($this->canggan[$bz2])
//                        if($this->wuxing[])
//                        {
//
//                        }
                    }
                }
            } // 地支
            else {

            }
        }
    }

    /**
     * 判断是否争财【男】或争官【女】
     * @param null $sex 性别 1 男 || 2 女
     * @param array $bazi 生成八字  1-8
     * @return bool true 是 ||  false 否
     */
    private function is_zc_zg($sex = null, $bazi = null)
    {
        if (($sex == 1 || !$sex != 2) || empty($bazi)) return false;
        $caixing_num = 0;// 财星
        $bijie_num = 0;// 比劫
        $guansha_num = 0;// 官杀
        $shishang_num = 0;// 食伤
        $yinxing_num = 0;// 印星
        if ($this->is_ygs($bazi[1], $bazi[5], '印')) $yinxing_num++;
        if ($this->is_ygs($bazi[3], $bazi[5], '印')) $yinxing_num++;
        if ($this->is_ygs($bazi[7], $bazi[5], '印')) $yinxing_num++;
        if ($this->is_ygs($bazi[1], $bazi[5], '财')) $caixing_num++;
        if ($this->is_ygs($bazi[3], $bazi[5], '财')) $caixing_num++;
        if ($this->is_ygs($bazi[7], $bazi[5], '财')) $caixing_num++;
        if ($this->is_ygs($bazi[1], $bazi[5], '官杀')) $guansha_num++;
        if ($this->is_ygs($bazi[3], $bazi[5], '官杀')) $guansha_num++;
        if ($this->is_ygs($bazi[7], $bazi[5], '官杀')) $guansha_num++;
        if ($this->is_ygs($bazi[1], $bazi[5], '比劫')) $bijie_num++;
        if ($this->is_ygs($bazi[3], $bazi[5], '比劫')) $bijie_num++;
        if ($this->is_ygs($bazi[7], $bazi[5], '比劫')) $bijie_num++;
        if ($this->is_ygs($bazi[1], $bazi[5], '食伤')) $shishang_num++;
        if ($this->is_ygs($bazi[3], $bazi[5], '食伤')) $shishang_num++;
        if ($this->is_ygs($bazi[7], $bazi[5], '食伤')) $shishang_num++;
        // 争财 天干财星仅一位，比劫一到两位，且天干无官杀食伤
        if ($sex == 1 && $caixing_num == 1 && $guansha_num == 0 && $shishang_num == 0
            && $bijie_num >= 1 && $bijie_num <= 2) {
            return true;
        } // 争官 天干官星仅一位，比劫一到两位，且天干无印星财星
        elseif ($sex == 2 && $guansha_num == 1 && $yinxing_num == 0 && $caixing_num == 0
            && $bijie_num >= 1 && $bijie_num <= 2) {
            return true;
        }
        return false;
    }

    /**
     * 十神关系  转化为单字显示
     * @param string $relation
     * @return string
     */
    private function shishen_to_easy($relation = '')
    {
        switch ($relation) {
            case '正财':
                return '财';
            case '偏财':
                return '才';
            case '正印':
                return '印';
            case '偏印':
                return '枭';
            case '食神':
                return '食';
            case '伤官':
                return '伤';
            case '比肩':
                return '比';
            case '劫财':
                return '劫';
            case '七杀':
                return '杀';
            case '正官':
                return '官';
            default:
                return '';
        }
    }

    /**
     * 纳音关系
     * @param null $gan 天干
     * @param null $zhi 地支
     * @return string
     */
    private function getNayin($gan = null, $zhi = null)
    {
        $nayin = '';
        switch ($gan . $zhi) {
            case '甲子':
            case '乙丑':
                $nayin = '海中金';
                break;
            case '丙寅':
            case '丁卯':
                $nayin = '炉中火';
                break;
            case '戊辰':
            case '己巳':
                $nayin = '大林木';
                break;
            case '庚午':
            case '辛未':
                $nayin = '路旁土';
                break;
            case '壬申':
            case '癸酉':
                $nayin = '剑锋金';
                break;
            case '甲戌':
            case '乙亥':
                $nayin = '山头火';
                break;
            case '丙子':
            case '丁丑':
                $nayin = '涧下水';
                break;
            case '戊寅':
            case '己卯':
                $nayin = '城头土';
                break;
            case '庚辰':
            case '辛巳':
                $nayin = '白蜡金';
                break;
            case '壬午':
            case '癸未':
                $nayin = '杨柳木';
                break;
            case '甲申':
            case '乙酉':
                $nayin = '井泉水';
                break;
            case '丙戌':
            case '丁亥':
                $nayin = '屋上土';
                break;
            case '戊子':
            case '己丑':
                $nayin = '霹雳火';
                break;
            case '庚寅':
            case '辛卯':
                $nayin = '松柏木';
                break;
            case '壬辰':
            case '癸巳':
                $nayin = '长流水';
                break;
            case '甲午':
            case '乙未':
                $nayin = '砂中金';
                break;
            case '丙申':
            case '丁酉':
                $nayin = '山下火';
                break;
            case '戊戌':
            case '己亥':
                $nayin = '平地木';
                break;
            case '庚子':
            case '辛丑':
                $nayin = '壁上土';
                break;
            case '壬寅':
            case '癸卯':
                $nayin = '金箔金';
                break;
            case '甲辰':
            case '乙巳':
                $nayin = '覆灯火';
                break;
            case '丙午':
            case '丁未':
                $nayin = '天河水';
                break;
            case '戊申':
            case '己酉':
                $nayin = '大驿土';
                break;
            case '庚戌':
            case '辛亥':
                $nayin = '钗钏金';
                break;
            case '壬子':
            case '癸丑':
                $nayin = '桑柘木';
                break;
            case '甲寅':
            case '乙卯':
                $nayin = '大溪水';
                break;
            case '丙辰':
            case '丁巳':
                $nayin = '砂中土';
                break;
            case '戊午':
            case '己未':
                $nayin = '天上火';
                break;
            case '庚申':
            case '辛酉':
                $nayin = '石榴木';
                break;
            case '壬戌':
            case '癸亥':
                $nayin = '大海水';
                break;
            default:
                break;
        }
        return $nayin;
    }

    /**
     * 空亡
     * @param null $gan 天干
     * @param null $zhi 地支
     * @return string
     */
    private function getKongwang($gan = null, $zhi = null)
    {
        $kongwang = '';
        $ganzhi = $gan . $zhi;
        if (in_array($ganzhi, ['甲子', '乙丑', '丙寅', '丁卯', '戊辰', '己巳', '庚午', '辛未', '壬申', '癸酉'])) {
            $kongwang = '戌亥';
        } elseif (in_array($ganzhi, ['甲戌', '乙亥', '丙子', '丁丑', '戊寅', '己卯', '庚辰', '辛巳', '壬午', '癸未'])) {
            $kongwang = '申酉';
        } elseif (in_array($ganzhi, ['甲申', '乙酉', '丙戌', '丁亥', '戊子', '己丑', '庚寅', '辛卯', '壬辰', '癸巳'])) {
            $kongwang = '午未';
        } elseif (in_array($ganzhi, ['甲午', '乙未', '丙申', '丁酉', '戊戌', '己亥', '庚子', '辛丑', '壬寅', '癸卯'])) {
            $kongwang = '辰巳';
        } elseif (in_array($ganzhi, ['甲辰', '乙巳', '丙午', '丁未', '戊申', '己酉', '庚戌', '辛亥', '壬子', '癸丑'])) {
            $kongwang = '寅卯';
        } elseif (in_array($ganzhi, ['甲寅', '乙卯', '丙辰', '丁巳', '戊午', '己未', '庚申', '辛酉', '壬戌', '癸亥'])) {
            $kongwang = '子丑';
        }
        return $kongwang;
    }

    /**
     * 八字格局
     * @param array $bazi
     * @return string
     */
    private function get_structure($bazi = [])
    {
        if (empty($bazi)) return '';
        $str = '';
        $geju = '';
        $yue_benqi = $this->canggan[$bazi[4]][0];

        $temp = [];

        $canggan = $this->canggan[$bazi[4]];// 月令藏干

        // 检测月令透干
        foreach ($canggan as $cg) {
            // 是否透出年干
            if ($this->wuxing[$cg] == $this->wuxing[$bazi[1]]) {
                if (!isset($temp[$this->wuxing[$bazi[1]]][$this->wuxing_yinyang[$bazi[1]]]))
                    $temp[$this->wuxing[$bazi[1]]][$this->wuxing_yinyang[$bazi[1]]] = 0;
                $temp[$this->wuxing[$bazi[1]]][$this->wuxing_yinyang[$bazi[1]]]++;
                $temp[$this->wuxing[$bazi[1]]]['zhi'] = $cg;
                $temp[$this->wuxing[$bazi[1]]]['gan'][] = $bazi[1];
                $temp[$this->wuxing[$bazi[1]]]['num'][] = 1;
            }
            // 是否透出月干
            if ($this->wuxing[$cg] == $this->wuxing[$bazi[3]]) {
                if (!isset($temp[$this->wuxing[$bazi[3]]][$this->wuxing_yinyang[$bazi[3]]]))
                    $temp[$this->wuxing[$bazi[3]]][$this->wuxing_yinyang[$bazi[3]]] = 0;
                $temp[$this->wuxing[$bazi[3]]][$this->wuxing_yinyang[$bazi[3]]]++;
                $temp[$this->wuxing[$bazi[3]]]['zhi'] = $cg;
                $temp[$this->wuxing[$bazi[3]]]['gan'][] = $bazi[3];
                $temp[$this->wuxing[$bazi[3]]]['num'][] = 3;
            }
            // 是否透出时干
            if ($this->wuxing[$cg] == $this->wuxing[$bazi[7]]) {
                if (!isset($temp[$this->wuxing[$bazi[7]]][$this->wuxing_yinyang[$bazi[7]]]))
                    $temp[$this->wuxing[$bazi[7]]][$this->wuxing_yinyang[$bazi[7]]] = 0;
                $temp[$this->wuxing[$bazi[7]]][$this->wuxing_yinyang[$bazi[7]]]++;
                $temp[$this->wuxing[$bazi[7]]]['zhi'] = $cg;
                $temp[$this->wuxing[$bazi[7]]]['gan'][] = $bazi[7];
                $temp[$this->wuxing[$bazi[7]]]['num'][] = 7;
            }
        }
//        dump($temp);
        // 月令为辰戌丑未
        if (in_array($bazi[4], ['辰', '戌', '丑', '未'])) {
            $str .= '杂气';
            // 若月令只透一种五行，且该五行非比肩劫财，则可依此确定格局；
            if (count($temp) == 1) {
                foreach ($temp as $w => $t) {
                    // 该五行非比肩劫财，则可依此确定格局；
                    if ($this->wuxing[$t['zhi']] != $this->wuxing[$bazi['5']]) {
                        $geju = $this->shishen[$t['zhi']][$bazi[5]] . "格";
                    }
                    // 若月令透出一种五行但有阴阳两干，
                    if (isset($t[0]) && isset($t[1])) {
                        // 正官七杀同在则取七杀格，正财偏财同现则以月令所藏为准，正印偏印同现也以月令所藏为准，食伤同现则取伤官格；
                        $_shishen = [];
                        foreach ($t['gan'] as $gan) {
                            $_shishen[] = $this->shishen[$gan][$bazi[5]];
                        }
                        if ($_shishen[0] == '七杀' || $_shishen[1] == '正官') {
                            $geju = '七杀格';
                        } elseif ($_shishen[0] == '正财' || $_shishen[1] == '偏财') {
                            $geju = $this->shishen[$t['zhi']][$bazi[5]] . '格';
                        } elseif ($_shishen[0] == '正印' || $_shishen[1] == '偏印') {
                            $geju = $this->shishen[$t['zhi']][$bazi[5]] . '格';
                        } elseif ($_shishen[0] == '食神' || $_shishen[1] == '伤官') {
                            $geju = '伤官格';
                        }
                        // 若月令只透一种五行且该五行为比肩劫财，则再观察其 所透是否为月令本气土，
                        // 若不是，则以月令本气定格，若是，则暂不取格。
                        if ($this->wuxing[$t['zhi']] == $this->wuxing[$bazi['5']] && $t['zhi'] != $yue_benqi) {
                            $geju = $this->shishen[$yue_benqi][$bazi[5]] . '格';
                        }
                    }
                    // 若月令透出五行阴阳与月令所藏不同，则以透出者为准；
                    if ((!isset($t[0]) || !isset($t[1])) && $w == $this->wuxing[$t['zhi']] && $t['zhi'] != $t['gan'][0]) {
                        $geju = $this->shishen[$t['gan'][0]][$bazi[5]] . '格';
                    }
                    if ($geju) break;

                }
            } // 若月令透出两种或三种五行，则分别视其为何种十神再分主次，优先取官杀、其次为财、再次为印星，最次为食伤；
            elseif (count($temp) > 1) {
                $tougan_shishen = [];
                foreach ($temp as $w => $t) {
                    // 遍历所透天干
                    foreach ($t['gan'] as $t_gan) {

                        $ts_shishen = $this->shishen[$t_gan][$bazi[5]];// 此处为所透天干，不是藏干

                        if (in_array($ts_shishen, ['正官', '七杀', '正财', '偏财', '正印', '偏印', '食神', '伤官'])) {
                            $tougan_shishen[] = $ts_shishen;
                        }
                    }
                }

                // 正官七杀同在则取七杀格，正财偏财同现则以月令所藏为准，正印偏印同现也以月令所藏为准，食伤同现则取伤官格；
                if (in_array('七杀', $tougan_shishen)) $geju = '七杀格';
                elseif (in_array('正官', $tougan_shishen)) $geju = '正官格';
                elseif (in_array('正财', $tougan_shishen) && in_array('偏财', $tougan_shishen)) {
                    foreach ($canggan as $cg) {
                        if ($this->shishen[$cg][$bazi[5]] == '正财') $geju = '正财格';
                        if ($this->shishen[$cg][$bazi[5]] == '偏财') $geju = '偏财格';
                    }
                } elseif (in_array('正财', $tougan_shishen)) $geju = '正财格';
                elseif (in_array('偏财', $tougan_shishen)) $geju = '偏财格';
                elseif (in_array('正印', $tougan_shishen) && in_array('偏印', $tougan_shishen)) {
                    foreach ($canggan as $cg) {
                        if ($this->shishen[$cg][$bazi[5]] == '正印') $geju = '正印格';
                        if ($this->shishen[$cg][$bazi[5]] == '偏印') $geju = '偏印格';
                    }
                } elseif (in_array('正印', $tougan_shishen)) $geju = '正印格';
                elseif (in_array('偏印', $tougan_shishen)) $geju = '偏印格';
                elseif (in_array('伤官', $tougan_shishen)) $geju = '伤官格';
                elseif (in_array('食神', $tougan_shishen)) $geju = '食神格';

            }

        } // 月令非辰戌丑未
        elseif (!in_array($bazi[4], ['辰', '戌', '丑', '未'])) {
            $yue_shishen = $this->shishen[$yue_benqi][$this->bazi[5]];
            if ($yue_shishen == '比肩') {
                $geju = '建禄格';
            } elseif ($yue_shishen == '劫财') {
                if (in_array($this->bazi[5], ['甲', '丙', '戊', '庚', '壬'])) $geju = '月刃格';
                else $geju = '月劫格';

            }

            if ($geju == '') {
                // 看月令本气五行是否透出。
                // 若不透则以月令所藏本气取格；

                // 若只透阴干或只透阳干则以所透之物取格。
                if (isset($temp[$this->wuxing[$yue_benqi]])) {
                    if (
                        (isset($temp[$this->wuxing[$yue_benqi]][0])
                            && !isset($temp[$this->wuxing[$yue_benqi]][1]))
                        || (isset($temp[$this->wuxing[$yue_benqi]][1])
                            && !isset($temp[$this->wuxing[$yue_benqi]][0]))
                    ) {
                        $geju = $this->shishen[$temp[$this->wuxing[$yue_benqi]]['gan'][0]][$bazi[5]] . '格';
                    }
                } else {
                    $geju = $this->shishen[$yue_benqi][$bazi[5]] . '格';
                }
                foreach ($temp as $w => $t) {
                    // 若透阴阳两干则参照第二步中蓝字部分；
                    if (isset($t[0]) && isset($t[1]) && count($temp) == 1) {
                        // 正官七杀同在则取七杀格，正财偏财同现则以月令所藏为准，
                        // 正印偏印同现也以月令所藏为准，食伤同现则取伤官格；
                        $_shishen = [];
                        foreach ($t['gan'] as $gan) {
                            $_shishen[] = $this->shishen[$gan][$bazi[5]];
                        }
                        if ($_shishen[0] == '七杀' || $_shishen[1] == '正官') {
                            $geju = '七杀格';
                        } elseif (in_array('正财', $_shishen) || in_array('偏财', $_shishen)) {
                            // 同在以月令所藏为准
                            if (in_array('正财', $_shishen) && in_array('偏财', $_shishen)) {
                                foreach ($canggan as $cg) {
                                    if ($this->shishen[$cg][$bazi[5]] == '正财') $geju = '正财格';
                                    if ($this->shishen[$cg][$bazi[5]] == '偏财') $geju = '偏财格';
                                }
                            } else {
                                $geju = $this->shishen[0] . '格';
                            }
                        } elseif ($_shishen[0] == '正印' || $_shishen[1] == '偏印') {
                            $geju = $this->shishen[$t['zhi']][$bazi[5]] . '格';
                        } elseif ($_shishen[0] == '食神' || $_shishen[1] == '伤官') {
                            $geju = '伤官格';
                        }

                    }
                    if ($geju) break;
                }
//                dump($temp);
            }
        }
        // 戊己日主生在辰戌丑未月份
        if ($geju === '') {
            // 若月支为辰
            if ($bazi[4] == '辰') {
                // 它支有申或子或亥，以癸水定格，前面加“通变”二字
                if (
                    in_array($bazi[2], ['申', '子', '亥'])
                    || in_array($bazi[6], ['申', '子', '亥'])
                    || in_array($bazi[8], ['申', '子', '亥'])
                ) {
                    $str = '通变';
                    $geju = $this->shishen['癸'][$bazi[5]] . '格';
                } // 它支同时有寅卯二字，则“七杀格”，加通变二字
                elseif (
                    ($bazi[2] == '寅' && ($bazi[6] == '卯' || $bazi[8] == '卯'))
                    || ($bazi[2] == '卯' && ($bazi[6] == '寅' || $bazi[8] == '寅'))
                    || ($bazi[6] == '寅' && ($bazi[2] == '卯' || $bazi[8] == '卯'))
                    || ($bazi[6] == '卯' && ($bazi[2] == '寅' || $bazi[8] == '寅'))
                    || ($bazi[8] == '寅' && ($bazi[2] == '卯' || $bazi[6] == '卯'))
                    || ($bazi[8] == '卯' && ($bazi[2] == '寅' || $bazi[6] == '寅'))
                ) {
                    $str = '通变';
                    $geju = '七杀格';
                }
            } // 若月支为戌
            elseif ($bazi[4] == '戌') {
                // 它支有寅或午或巳，则以丁火定格，加通变二字
                if (
                    in_array($bazi[2], ['寅', '午', '巳'])
                    || in_array($bazi[6], ['寅', '午', '巳'])
                    || in_array($bazi[8], ['寅', '午', '巳'])
                ) {
                    $str = '通变';
                    $geju = $this->shishen['丁'][$bazi[5]] . '格';
                } // 它支同时有申酉二字，则“伤官格”，加通变二字
                elseif (
                    ($bazi[2] == '申' && ($bazi[6] == '酉' || $bazi[8] == '酉'))
                    || ($bazi[2] == '酉' && ($bazi[6] == '申' || $bazi[8] == '申'))
                    || ($bazi[6] == '申' && ($bazi[2] == '酉' || $bazi[8] == '酉'))
                    || ($bazi[6] == '酉' && ($bazi[2] == '申' || $bazi[8] == '申'))
                    || ($bazi[8] == '申' && ($bazi[2] == '酉' || $bazi[6] == '酉'))
                    || ($bazi[8] == '酉' && ($bazi[2] == '申' || $bazi[6] == '申'))
                ) {
                    $str = '通变';
                    $geju = '伤官格';
                }
            } // 若月支为丑
            elseif ($bazi[4] == '丑') {
                // 它支有巳或酉或申，则“伤官格”，加通变二字
                if (
                    in_array($bazi[2], ['酉', '申', '巳'])
                    || in_array($bazi[6], ['酉', '申', '巳'])
                    || in_array($bazi[8], ['酉', '申', '巳'])
                ) {
                    $str = '通变';
                    $geju = '伤官格';
                } // 它支同时有亥子二字，则以癸水定格，加通变二字
                elseif (
                    ($bazi[2] == '亥' && ($bazi[6] == '子' || $bazi[8] == '子'))
                    || ($bazi[2] == '子' && ($bazi[6] == '亥' || $bazi[8] == '亥'))
                    || ($bazi[6] == '亥' && ($bazi[2] == '子' || $bazi[8] == '子'))
                    || ($bazi[6] == '子' && ($bazi[2] == '亥' || $bazi[8] == '亥'))
                    || ($bazi[8] == '亥' && ($bazi[2] == '子' || $bazi[6] == '子'))
                    || ($bazi[8] == '子' && ($bazi[2] == '亥' || $bazi[6] == '亥'))
                ) {
                    $str = '通变';
                    $geju = $this->shishen['癸'][$bazi[5]] . '格';
                }
            } // 若月支为未
            elseif ($bazi[4] == '未') {
                // 它支有亥或卯或寅，则“七杀格”，加通变二字
                if (
                    in_array($bazi[2], ['亥', '卯', '寅'])
                    || in_array($bazi[6], ['亥', '卯', '寅'])
                    || in_array($bazi[8], ['亥', '卯', '寅'])
                ) {
                    $str = '通变';
                    $geju = '七杀格';
                } // 它支同时有巳午二字，则以丁火定格，加通变二字
                elseif (
                    ($bazi[2] == '巳' && ($bazi[6] == '午' || $bazi[8] == '午'))
                    || ($bazi[2] == '午' && ($bazi[6] == '巳' || $bazi[8] == '巳'))
                    || ($bazi[6] == '巳' && ($bazi[2] == '午' || $bazi[8] == '午'))
                    || ($bazi[6] == '午' && ($bazi[2] == '巳' || $bazi[8] == '巳'))
                    || ($bazi[8] == '巳' && ($bazi[2] == '午' || $bazi[6] == '午'))
                    || ($bazi[8] == '午' && ($bazi[2] == '巳' || $bazi[6] == '巳'))
                ) {
                    $str = '通变';
                    $geju = $this->shishen['丁'][$bazi[5]] . '格';
                }
            }
        }
        // 以上皆非则“无主格”
        if ($geju === '') {
            $geju = '无主格';
        }

        $fenge = '';
        // 检测格局成败及用神划分，定分格
        if ($geju == '正官格') {

        } elseif ($geju == '正财格' || $geju == '偏财格') {

        } elseif ($geju == '七杀格') {

        } elseif ($geju == '正印格' || $geju == '偏印格') {

        } elseif ($str == '杂气' && $geju == '食神格') {

        } elseif ($geju == '伤官格') {

        } elseif ($geju == '建禄格') {

        } elseif ($geju == '月劫格') {

        } elseif ($geju == '月刃格') {

        }
        if ($geju == '无主格') $str = '';

        return $str . $geju . $fenge;
    }
}
